Spring MVC Annotation Development
<context:component-scan base-package= "Com.controls"/>
SPRINGMVC Scanner
Because of the use of note-based controllers, this specifies the path of the package that needs to be scanned, if more than one can be separated using commas
<mvc:annotation-driven/> Annotation Driver
Dispatcherservlet takes over the request, the mapping is performed by handlermapping, so we need to register the hanldermapping, for example, the label above will be automatically registered, such as defaultannotationhandlermapping (the mapping that performs the request to the Controller) and Annotationmethodhandleradapter (invoking the method in the controller), Of course, this tag also provides some other support
[Email protected] is the most commonly used annotation in SPRINGMVC, which can help define the current class as a spring-managed bean, specifying that the class is a controller that can be used to accept requests
@controller: Identifying the current class is a concrete implementation of the control layer
[email protected] will default to the current class name for the spring bean, or can be customized, such as: @Controller ("Logincontroller") set the current bean name is Logincontroller
3. @requestMapping: Put on the method above to specify the path of a method, when it is placed on the class equivalent to the namespace needs to be requestmapping on the combination method to access.
Note Name |
Role |
@Controller |
Annotations indicate that the class requires the spring container to be loaded automatically, and a class to be the Bean of the spring container. |
@RequestMapping |
It can be labeled at the class definition, associating a Controller with a specific request, or it can be labeled at the method signature. So the @RequestMapping labeled at the class declaration is equivalent to having POJO implement the Controller interface, and the @RequestMapping at the method definition is equivalent to having the POJO extend the Spring predefined controller (such as Simp Leformcontroller, etc.). |
@Resource |
The setter method parameter that is used to annotate the attribute is derived from the spring Bean |
@ModelAttribute |
① bind request parameter to command object: When placed on the parameter of the function processing method, it is used to bind multiple request parameters to a command object, thus simplifying the binding process and automatically exposing the model data for use in view page presentation; ② exposes a form reference object as model data: when placed on a processor's general method (non-functional processing method), it is the form reference object that prepares the form for presentation, such as the city that needs to be selected when registering, and before performing the function processing method (@RequestMapping annotation method), Automatically added to the model object for use when the view page is displayed; ③ Exposure @requestmapping method returns a value of model data: when placed on the return value of a function processing method, the return value of the exposed function processing method is the model data that is used when the view page is displayed. |
@SessionAttributes |
Represents the annotated object that is stored in the httpsession scope |
@PathVariable |
Used to map template variables in the request URL to parameters of a functional processing method |
@requestParam |
Used to map the request parameter area data to the parameters of a functional processing method |
Springmvc Getting Started 2-annotation development