Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use @ RequestMapping annotations in Spring MVC

Shulou Source: shulou.com Published: 2022-06-02 06:03:40 10月25日 Update

Today, I will talk to you about how to use @ RequestMapping annotations in Spring MVC. Many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something from this article.

The @ RequestMapping annotation and RequestMappingHandlerMapping work together, so first figure out the attributes in @ RequestMapping. The @ RequestMapping annotated class function will be packaged and stored as a RequestMappingInfo object, and when a http request is received, it will find a best match according to request.

Name

The name attribute is a name for the RequestMapping, but I haven't found out what it does.

Value 、 path

The request path for http, which can be either a regular expression or a parameter placeholder. If this property is written at the class level, then other methods annotated by @ RequestMapping in the class class will be useful.

Method

Http request method, GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACE. If this property is written at the class level, then other methods annotated by @ RequestMapping in the class class will be useful.

Params

The qualification of the parameter, the way the expression is expressed. MyParamroomroommyValue indicates that there must be a parameter with the name "myParam" and a value not equal to "myValue". Or myParam=myValue, myParam means that there must be a parameter named "myParam", and the parameter value can be arbitrary. ! myParam indicates that it must not contain the parameter "myParam".

If this property is written at the class level, then other methods annotated by @ RequestMapping in the class class will be useful.

Headers

This headers is used in the same way as params. It represents the request header of the http. If this property is written at the class level, then other methods annotated by @ RequestMapping in the class class will be useful.

Consumes

Represents the "Content-Type" request header in the http request header. Such as text/plain "," application/*. If this property is written at the class level, then other methods annotated by @ RequestMapping in the class class will be useful.

Produces

Represents the Accept request header in the http request header, assuming your Accept=application/json, then the request will be more accurately mapped to the produces=application/json method. If this property is written at the class level, then other methods annotated by @ RequestMapping in the class class will be useful.

After reading the above, do you have any further understanding of how to use the @ RequestMapping annotation in Spring MVC? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Tags: Annotations methods actions properties parameters levels contents names expressions same precise usage methods functions names objects methods times more best regular Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Apple Microsoft Xiaomi OPPO Reno