SpringMVC annotations

SpringMVC annotations

1.
@Controller @Controller is used to mark a class, and the class marked with it is a SpringMVC Controller object. The dispatch processor will scan the method of the class that uses the annotation, and detect whether the method uses the @RequestMapping annotation. @Controller just defines a controller class, and the method annotated with @RequestMapping is the processor that actually processes the request

2.
@RequestMapping @RequestMapping is an annotation used to process request address mapping, which can be used on classes or methods. Used on classes, it means that all methods in the class that respond to requests use this address as the parent path.

3. @Autowired
@Autowired is used when doing bean injection and can be written on fields and setter methods. If it is written on the field, then there is no need to write setter methods.

4. @ModelAttribute and @SessionAttributes
Before calling all methods of the Controller , execute this @ModelAttribute method, which can be used in annotations and method parameters, so that when the Controller is called, the @ModelAttribute method is executed first.

@SessionAttributes puts the value in the session scope and writes it on the class.

5. @PathVariable
@PathVariable is used to map the template variable in the request URL to the parameter of the function processing method, that is, take the variable in the URL template as a parameter

6,
@RequestParam @RequestParam is mainly used to obtain parameters in the SpringMVC background control layer, similar to Request.getParameter("name")

7.
@ResponseBody @ResponseBody This annotation is used to convert the object returned by the Controller method into a specified format through an appropriate HttpMessageConverter, and then write it to the body data area of ​​the Response object.

Use: Use when the returned data is not a page with html tags, but data in some other format (such as json, xml, etc.);

8. @Component is
equivalent to a general annotation. It is used when you don't know which layer some classes belong to, but it is not recommended.

9. @Repository is
used to annotate the dao layer and annotate on the dao implementation class.

Guess you like

Origin blog.csdn.net/weixin_49092628/article/details/109955916