@RequestMapping("/response")
public ResponseEntity<String> Headers(HttpServletRequest request) throws IOException {
//解析请求参数,解析请求体,解析响应体
HttpHeaders responseHeaders = new HttpHeaders();
String jsonStr = Files.readString(Path.of("data.json"));
JSONObject jsonObj = JSON.parseObject(jsonStr);
jsonObj.putAll(request.getParameterMap());
jsonObj.put("dataUrl",request.getRequestURL());
ResponseEntity<String> result = ResponseEntity.ok().headers(responseHeaders).body(jsonObj.toString());
return result;
}
java 解析spring boot 设置响应体和解析请求参数
于 2024-04-11 20:44:45 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)