SpringMVC obtains request parameters, request headers, and cookie information

Get request parameters by default

Directly write a variable with the same name as the request parameter name on the method input parameter. This variable is used to receive the value of the parameter.

@Controller
public class ParamController {
    
    

    @RequestMapping("/handle01")
    public String handle01(String username){
    
    
        System.out.println("获取到的请求参数是:"+username);
        return "success";
    }
}

Request made:

http://localhost:8088/springMVC/handle01?username=hello

result
insert image description here

@RequestParam gets request parameters

Specify which parameter value to get by @RequestParam

    @RequestMapping("/handle01")
    public String handle01(@RequestParam("user") String username){
    
    
        System.out.println("获取到的请求参数是:"+username);
        return "success";
    }

Request sent

http://localhost:8088/springMVC/handle01?user=hello

@RequestHeader

He can get a value in the request header. Equivalent to request. getHeader();

@CookieValue

He can get the value of a cookie.
insert image description here

Guess you like

Origin blog.csdn.net/weixin_42643321/article/details/107672957