1、获取请求体使用的是HttpEntity
类
/**
* 获取请求体信息
* @param httpEntity
* @return
*/
@RequestMapping("/test")
public String test(HttpEntity<String> httpEntity){
System.out.println(httpEntity);
String body = httpEntity.getBody();
return "success";
}
2、定制响应内容使用ResponseEntity
类
/**
* 自定义响应相关信息,包含body、header
* @return
*/
@RequestMapping("/testResponseEntity")
public ResponseEntity<String> testResponseEntity(){
String body = "<h1>hello</h1>";
MultiValueMap<String,String> header = new HttpHeaders();
header.add("Set-Cookie","name=zhangsan");
return new ResponseEntity<String>(body,header, HttpStatus.OK);
}