0

请在下面找到我的控制器代码。

@RequestMapping(value = "/reconrangesummary", method=RequestMethod.POST, produces=MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public String getReconRangeSummaryReport(@RequestBody RequestData requestData){
    logger.info("Inside Interest Service Controller - getReconRangeSummaryReport");
    List<ReconRangeSummaryDetails> reconRangeSummaryDetails = new ArrayList<ReconRangeSummaryDetails>();
    DashboardRequestDetails requestDetails = AccountUtils.convertRequest(requestData);
    reconRangeSummaryDetails = accountService.getReconRangeSummaryDetails(requestDetails);
    logger.info("Exit Interest Service Controller - getReconRangeSummaryReport");

    return new Gson().toJson(reconRangeSummaryDetails);

}

请求数据类:

public class RequestData {

private String role;
private String branchCode;
private String circle;
private String requestDate;
public String getRole() {
    return role;
}
public void setRole(String role) {
    this.role = role;
}
public String getBranchCode() {
    return branchCode;
}
public void setBranchCode(String branchCode) {
    this.branchCode = branchCode;
}
public String getCircle() {
    return circle;
}
public void setCircle(String circle) {
    this.circle = circle;
}
public String getRequestDate() {
    return requestDate;
}
public void setRequestDate(String requestDate) {
    this.requestDate = requestDate;
}

我正在使用POST 方法和 content-type:application/json在邮递员中传递以下请求。

{"role":"makeruser", "branchCode":"00112", "circle":"circlename", "requestDate":"17-12-2018"}   

但我收到如下错误响应。

HTTP 状态 415
服务器拒绝此请求,因为请求实体的格式不受所请求方法 () 的请求资源支持。

4

1 回答 1

0

在发布您的请求时,您也必须在这种情况下指定 JSON/应用程序媒体类型。如果您使用 Postman,请更改以下复选框:在此处输入图像描述

或者如果需要,可以使用命令行版本:

curl -d '{"role":"makeruser", "branchCode":"00112", "circle":"circlename", "requestDate":"17-12-2018"}' -H "Content-Type: application/json" -X POST http://localhost:9009/new/reconrangesummary
于 2019-02-21T14:31:24.650 回答