Explanation
Source: @Target({ElementType.METHOD, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Documented @Mapping public @interface RequestMapping { } effect: For establishing a correspondence between the request URL and requests processing method
appears positions:
the Class:
request URL of the first stage to access the directory. Do not write here, then, is equivalent to the root directory of the application. Need to write the words / beginning.
The purpose is to make it appear our URL can follow a modular management :
for example:
account module:
/ the Account / the Add
/ the Account / Update
/ the Account / the Delete
...
Order Module:
/ the Order / the Add
/ the Order / Update
/ the Order / delete
the red part is to RequsetMappding written in the class, so that our URL more sophisticated.
The method:
request URL second-level access to the directory.
Attribute:
value : request for designating the URL . It and pathThe role of property is the same.
Method : specify a request.
the params : for the request parameters specified condition. It supports simple expression. Required request parameters of key and value must be
configured exactly the same.
For example:
the params = { "accountName"} , the parameter indicates that the request must be accountName
the params = { "moeny 100!"} , Indicates the request parameters money can not be 100 .
headers : restriction request message header is used to specify the conditions.
Note: The
above four properties appear as long as 2 Shi or more, their relationship is with
method Example
Controller code
/** * Save Account * @return */ @RequestMapping(value="/saveAccount",method=RequestMethod.POST) public String saveAccount() { . System OUT .println ( " Save the accounts " ); return " Success " ; }
jsp code
<! - Request exemplary embodiment -><a href= "account/saveAccount"> saving accounts, GET requests </a> <br/> <form action="account/saveAccount" method="post"> <INPUT type = " Submit " value = " saving accounts, post Request " > </form>
When using a get request, an error message is 405 , the information is a method does not support get way request
params example
Controller code
/** * Delete Account * @return */ @RequestMapping(value="/removeAccount",params= {"accountName","money>100"}) public String removeAccount() { . System OUT .println ( " delete account " ); return " Success " ; }
jsp code
<! - exemplary request parameters -> href= <a "account/removeAccount?accountName=aaa&money> 100 " > delete the account, the amount of 100 </a> <br/> href= <a "account/removeAccount?accountName=aaa&money> 150 " > delete the account, the amount of 150 </a>
When we click on a hyperlink , you can visit a success.
When we click the second hyperlink, inaccessible. As shown below:
Examples headers
Controller code