Решено .. Проблема в том, что я отправил пустой массив reauestData [], но теперь я изменил массив на объект json
{
"data": [
{"columnname": "symbol", "filterby": "", "values": "", "time": "", "datatype": "String"}, {"columnname":"order_Receiving_Date", "filterby": "", "ценности": "", "время": "", "тип данных": "DateRange"}, { "имя_столбца": "EVENT_TYPE", "filterby": "","ценности": "", "время": "", "Тип данных": "String"}, { "имя_столбца": "firm_ROE_ID", "filterby": "", "ценности": "", "время":"", "тип данных": "Int"}, { "имя_столбца": "rejected_ROE_ID", "filterby": "", "ценности": "", "время": "", "тип данных": "Int"}
]
}
Метод отправки
component.ts
prepareData() {
console.log("this.FilterData"+JSON.stringify(this.FilterData));
this.loading = true;
this.SharedHttpClientService.post(
this.UrlsService.setAPIURl(
APIURL.Surveillance_OatsException_Summary),
this.FilterData)
.map((response: Response) => {
this.isLoadingResults = false;
this.isRateLimitReached = false;
return response.json();
})
.subscribe(Element => {
this.dataset=Element;
},
(err: HttpErrorResponse) => {
this.isLoadingResults = false;
this.isRateLimitReached = true;
});
this.loading = false;
}
service.ts
private attachAuthorization(): RequestOptions {
const headers = new Headers();
headers.append('Content-Type', 'application/json');
//headers.append('HttpHeaders.ACCEPT', 'MediaType.APPLICATION_JSON_VALUE');
headers.append ('Authorization',sessionStorage.getItem('token'));
//console.log(localStorage.getItem('token'));
const options = new RequestOptions({
headers: headers,
responseType: ResponseContentType.Json,
});
return options;
}
public post(url: string, requestData: any):Observable<any>{
const options = this.attachAuthorization();
//console.log(localStorage.getItem('token'));
let Data={"data":requestData}
console.log("Data "+JSON.stringify(Data));
return this.http.post(url,JSON.stringify(Data),options);
}
API-контроллер Функция
@RequestMapping(value = {"/Oats-Exception-summary/"}, method = RequestMethod.POST)
public ResponseEntity<List<OatsExceptionSummary>> OatsExceptionSummaryPost(
@RequestBody Map payload)throws SQLException,JSONException,Exception {
JSONObject root = new JSONObject( payload);
JSONArray dataArray = root.getJSONArray("data");
for (int t=0; t<dataArray.length(); t++) {
JSONObject JObject = dataArray.getJSONObject(t);
System.out.println(JObject.getString("columnname"));
}
String FilterData="";
//JSONObject jsonObj=new JSONObject(payload);
List<OatsExceptionSummary> Data =ISurveillanceService.getOatsExecptionSummary(FilterData);
if (Data.isEmpty()) {
return new ResponseEntity<List<OatsExceptionSummary>>(HttpStatus.NO_CONTENT);
} else {
return new ResponseEntity<List<OatsExceptionSummary>>(Data, HttpStatus.OK);
}
}