Spring MVC:请求主体中JSONObject的请求映射

时间:2017-04-28 06:37:09

标签: java spring rest

import org.json.JSONObject;


    @RequestMapping(value = "/uploadMultipleFile", method = RequestMethod.POST,consumes = "application/json")

        public @ResponseBody void uploadMultipleFileHandler(@RequestBody JSONObject validationData,HttpServletRequest request, HttpServletResponse response) {
            System.out.println(validationData);
    }

我无法将此请求表格映射到邮递员。它给了我错误:description The request sent by the client was syntactically incorrect.

但是如果我将JSONObject更改为String,那么它的工作形式为POSTMAN。

1 个答案:

答案 0 :(得分:0)

你试过吗?
使用@RequestBody Map<String, Object> validationData代替@RequestBody JSONObject validationData 希望这会对你有所帮助。

    public void getValues(@RequestBody Map<String, Object> validationData, final HttpServletRequest request, final HttpServletResponse response) {
         System.out.println(pvmValues.get("key"));
     }