Java获取POST请求Json格式参数(raw)

 

在这里插入图片描述

 

有两种方式:

1、已流的方式接收请求参数

// request为HttpServletRequest对象
BufferedReader br = null;
try {
    br = new BufferedReader(new InputStreamReader(request.getInputStream(), "UTF-8"));
} catch (IOException e) {
    e.printStackTrace();
}
String line = null;
StringBuilder sb = new StringBuilder();
try {
    while ((line = br.readLine()) != null) {
        sb.append(line);
    }
    br.close();
} catch (IOException e) {
    e.printStackTrace();
}

 

2、@RequestBody注解 接收

 

@RequestMapping(value = "/technicalReviewInfo", method = RequestMethod.POST,produces = "application/json;charset=utf-8")
@ResponseBody
public JSONObject synTechnicalReviewInfo(@RequestBody JSONObject technicalReviewJson) {
    JSONObject json=new JSONObject();
    return json;
}

 

      转自:https://blog.csdn.net/weixin_42096792/article/details/121661148
posted @ 2022-06-22 10:54  ToDarcy  阅读(5636)  评论(0编辑  收藏  举报