错误-错误的请求;检查错误消息以获取详细信息

时间:2018-12-04 09:14:55

标签: java spring spring-mvc

我用spring创建了API。当我调用该API时显示错误

这是Controller类。

@RequestMapping(value={"/dPIUsagePackageInfo"},method=RequestMethod.POST)
  public ResponseEntity<DPIUsagePackageInfoRs> dPIUsagePackageInfo(@RequestBody List<DPIUsagePackageInfoRq> dPIUsagePackageInfoRq){

      //
      DPIUsagePackageInfoRs response = this.ccbsBusiness.dPIUsagePackageInfo(dPIUsagePackageInfoRq);
      return new ResponseEntity(response, response.getStatus());
  }

这是Request类

public class DPIUsagePackageInfoRq {    

    private List<String> srvName;


    public List<String> getSrvName() {
        return srvName;
    }

    public void setSrvName(List<String> srvName) {
        this.srvName = srvName;
    }


}

我通过了这个json正文

{
    "dPIUsagePackageInfoRq" : {
        "srvName": ["xxx","rrr","rrrrr"]
    }
}

但是这样的回应

{
    "resultCode": "000400",
    "resultDesc": "ERROR - Bad request; check the error message for details."
}

我的代码哪里出了问题。感谢进阶。

1 个答案:

答案 0 :(得分:1)

您仅发送一个DPIUsagePackageInfoRq实例,应在列表中将其发送。请尝试在身体的开头和结尾添加“ [”和“]”,以使其成为列表。

您要发送的请求应如下:

[
    {
        "srvName": ["xxx","rrr","rrrrr"]
    }
]

,如果您想发送多个DPIUsagePackageInfoRq对象,则可以使用增量对象,如下所示:

[
    {
        "srvName": ["xxx","rrr","rrrrr"]
    },
    {
        "srvName": ["xxx","rrr","rrrtrr"]
    }
]