SpringMVC-RequestEntity类型

一、介绍
RequestEntity类型用于获取整个请求报文,包括请求头、请求体等信息。

二、项目测试
(1)编写Controller类

@Controller
public class MyController {

    @RequestMapping(value = {"/hello"})
    public String hello(RequestEntity<String> requestEntity){
        HttpHeaders headers = requestEntity.getHeaders();
        String body = requestEntity.getBody();
        URI url = requestEntity.getUrl();
        HttpMethod method = requestEntity.getMethod();
        System.out.println("请求头:" + headers.toString());
        System.out.println("请求体:" + body);
        System.out.println("URL:" + url.toString());
        System.out.println("请求方法:" + method.toString());
        return "hello";
    }
}

(2)运行
SpringMVC-RequestEntity类型_第1张图片
SpringMVC-RequestEntity类型_第2张图片

你可能感兴趣的:(SpringMVC,后端,java)