下面是rest控制器类,它是post请求
@PostMapping(value = "/details")
public SubSeriesDetailsRequest getGlobalSearchProductDetails(@RequestBody List<SubSeriesCodesRequest> codes,
@QueryParam("contextString") String contextString) {
LOGGER.info("Inside post request " + codes);
String url = "http://www.example.com/details";
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<Object> entity = new HttpEntity<>(headers);
// SubSeriesDetailsRequest detailsRequest = new SubSeriesDetailsRequest();
SubSeriesDetailsRequest response = restTemplate.postForObject(url, entity, SubSeriesDetailsRequest.class);
return response;
}
我的dto类
@jsoninclude(jsoninclude.include.non\u null)@jsonignoreproperties(ignoreunknown=true)
公共类subscriescodesrequest实现可序列化{
private static final long serialVersionUID = 6880035785505252493L;
private List<String> codes;
public SubSeriesCodesRequest(List<String> codes) {
super();
this.codes = codes;
}
@JsonCreator
public SubSeriesCodesRequest() {
}
public List<String> getCodes() {
return codes;
}
public void setCodes(List<String> codes) {
this.codes = codes;
}
需要实现如下post请求
1条答案
按热度按时间qqrboqgw1#
您的请求与预期模型不匹配。你是说你希望
List
的SubSeriesCodesRequest
你正在发送一个字符串数组。您当前的模型如下所示:
试着把你的方法改成这样
public SubSeriesDetailsRequest getGlobalSearchProductDetails(@RequestBody SubSeriesCodesRequest request,
它应该能正常工作。