SpringMvc common annotations

1.@controller

Define a control class to mark a class, and the class marked with it is a springMvc object.

2.@RequestMapping

RequestMapping is an annotation used to process request address mapping (mapping requests to corresponding controller methods), which can be used on classes or methods. Used on a class, indicating that all methods in the class that respond to requests use this address as the parent path.

3.@requestParam 

Get the parameters of the requested url such as /requestparam1?username=zhang

public String requestparam4(@RequestParam(value="username",required=false) String username)

4. @responseBody 

    Convert the object returned by the Controler method to a json type string

 

5.@RequestBody

    Convert json type string to object or Map, list

 

6. @ PathVariable

The binding url template variable value is used to map the template variable in the request URL to the parameter of the function processing method. 

That is, the variables in the url can be bound to the parameters of the method through the PathVariable.

@RequestMapping(value="/users/{userId}/topics/{topicId}")

public String test(
       @PathVariable(value="userId") int userId, 
       @PathVariable(value="topicId") int topicId)



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326006832&siteId=291194637