SpringMVC foundation--@RequestMapping annotation

Role: used to establish the correspondence between the request URL and the processing method of the request.
It can act on a class or a method. When acting on a class, it is equivalent to all the methods in the class, and all requests that must be processed must be subpaths under the path that should act on the class.
Attributes:

 /*
    * 属性:
    *   value和path: 指定请求路径
    *   method:指定请求方式,通过调用RequestMethod的枚举类型指定(GET、POST等),非该方式的请求不处理
    *   params: 指定请求参数,key和value的值必须与指定的一样,只要key则要求有该参数就行。
    *   headers: 指定请求头,用不到。
    * */
    @RequestMapping(value = "/hello",method = RequestMethod.GET,params = {
    
    "username"})
    public String sayHello() {
    
    
        System.out.println("Hello SpringMVC");
        return "hello";
    }

value and path:
Specify the path to process the request. When there is only this parameter, the attribute name can be omitted.
method:
Specify the request method, for example: @RequestMapping ("/hello", method = RequestMethod.POST), that is, only POST requests can be processed, and all other requests will be processed. If the request method is different from the specified method, an error will be reported using
insert image description here
params Used to specify conditions that restrict request parameters. It supports simple expressions. It is required that the key and value of the request parameter must be exactly the same as the configuration, and this parameter is required when no value is specified.
For example:

RequestMapping(value = "/hello",params = {
    
    "username"})

When there is no such parameter in the request, an error will be reported, and
insert image description here
the specified parameter needs to be added to the request
<a href="hello?username=haha">开始测试</a>

wildcard

–?: /hello/qqq? matches a single character in a filename

– *: /hello/* /yes matches any character in the filename

– Two Star Flowers: ** match multi-level paths

Guess you like

Origin blog.csdn.net/qq_44660367/article/details/108909922