For various annotations, the first is of course "@Controller", indicating that a class is a Controller.
The "@RequestMapping" request path mapping, if labeled at the class level of a controller, indicates that access to the method under such a path is accompanied by the path of its configuration, most commonly labeled on the method, indicating which specific method is used to accept processing of a request.
@Controller @requestmapping (value= "/book") public class Bookcontroller {@RequestMapping (value= "/title") public String GetTitle () {return ' title ';} @RequestMapping (value= "/content") public String getcontent () {return "content";}}
Since the Bookcontroller class adds "@RequestMapping" annotations to the Value= "/book", all related paths are prefixed with "/book", that is, the requested URLs are:
- Http://localhost:8080/book/title
- http://localhost:8080/book/content
" /" before and after "@RequestMapping" value has no effect on the requested path, that is, value= "book", "/book", "/book/" have the same effect
properties for "@RequestMapping"
- Value: Specifies the actual URL of the request
1. Normal specific values. As in the previous value= "/book".
2. A class of values with a variable
@RequestMapping (value= "/get/{bookid}") public string Getbookbyid (@PathVariable string Bookid,model Model) { Model.addattribute ("BookId", bookId); return "book";}
the BookID in the path can be used as a variable, @PathVariable annotation to extract the value of a variable in the path
3.ant style
@RequestMapping (value= "/get/id?") : Can match "/get/id1" or "/get/ida", but does not match "/get/id" or "/GET/IDAA";
@RequestMapping (value= "/get/id*"): Can Match "/get/idabc" or "/get/id", but does not match "/GET/IDABC/ABC";
@RequestMapping (value= "/get/id/*"): Can Match "/GET/ID/ABC", but does not match "/GET/IDABC";
@RequestMapping (value= "/get/id/**/{id}"): Can Match "/get/id/abc/abc/123" or "/get/id/123", that is, ant style and URI template variable style can be mixed;
4. A class of values with regular expressions
@RequestMapping (value= "/get/{idpre:\\d+}-{idnum:\\d+}"): Can Match "/get/123-1", but cannot match "/get/abc-1", so you can design stricter rules.
can be done by@PathVariable Annotations Extract the variables in the path (idpre,idnum)
5. or relationship
@RequestMapping (value={"/get", "/fetch"}) that is/get or/fetch are mapped to the method
- Method: Specifies the type of method requested, GET, POST, PUT, delete, and so on;
@RequestMapping (value= "/get/{bookid}", method={requestmethod.get,requestmethod.post})
- Params
@RequestMapping (params= "Action=del"), the request parameter contains "Action=del", such as: Http://localhost:8080/book?action=del
- Headers
@RequestMapping (value= "/header/id", headers = "Accept=application/json"): Indicates that the requested URL must be "/header/id and that the request header must have" Accept = Application/json "parameter to match.
"3" SPRINGMVC common annotations of @controller and @requestmapping