1. requestmapping Annotation Application
@RequestMapping can be used on class definitions and method definitions
@RequestMapping indicate which customer request this class or method corresponds to
Turn on the @requestmapping annotation map, Need to define the requestmappinghandlermapping (before class definition) and Requestmappinghandleradapter (before the method definition) two bean components in the spring XML configuration file
Tips:
Defaultannotationhandlermapping and Annotationmethodhandleradapter two components need to be defined before Spring3.1 version
Requestmappinghandlermapping and requestmappinghandleradapter Two bean component definition examples
<!-- requestmappinghandlermapping --> bean class = " Org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping " /> <!-- --> bean class = "Org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter" />
Starting with the Spring3.2 version, you can use the following XML configuration to simplify the requestmappinghandlermapping and Requestmappinghandleradapter definitions
</>
2. Controller annotation Application
It is recommended to declare the controller component using the @controller annotation, which makes the controller definition more flexible, without implementing the Controller interface, and the method of request processing can be flexibly defined
@Controller
For the @controller annotation to take effect, the component scan definition needs to be turned on in the spring XML configuration file, and the package containing the controller component is specified
<!-- opening @controller Annotations - < base-package= "Com.tarena.controller"/>
MVC apps based on annotation configuration