First, note: version issues
spring3.2 Previous versions, the annotated mapper and adapter used the following two classes.
Org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping. class Org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter. class
In the new version of the source code, you can see the following comments:
The following classes are used in the 3.2 included and later versions:
Org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping. class Org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter. class
Ii. differences between the use of annotations and non-annotations
1. When using non-annotations, only one method can be implemented in the controller, the method name and parameters are fixed, and multiple methods cannot be used.
2. Allows you to customize any method when using annotations.
Third, the shorthand way of annotations
Below, provides a simpler annotation configuration method that can be used directly in a production environment.
<!-- -<!-- - <!-- Simplified Note Processor Mapper and adapter: Contains not only the above mapper and adapter, but also loads a lot of parameter binding methods - < Mvc:annotation-driven></mvc:annotation-driven>
Iv. Development process
1. Modify the Springmvc.xml file as follows:
<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xmlns:p= "http://www.springframework.org/schema/p"Xmlns:context= "Http://www.springframework.org/schema/context"Xmlns:mvc= "Http://www.springframework.org/schema/mvc"XMLNS:AOP= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"Xmlns:tx= "Http://www.springframework.org/schema/tx"xsi:schemalocation= "Http://www.springframework.org/schema/beans Http://www.springframework.org/schema/beans/spring-beans. XSD Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-conte Xt-4.3.xsd Http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4 .3.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP Http://www.springframework.org/schema/aop/spring-aop-4.3.xs D http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.x SD "> <!--<bean class= "org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" >< /bean> -<!--<bean class= "Org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter" >< /bean> - <!--Simplified Note Processor Mapper and adapter: Contains not only the above mapper and adapter, but also loads a number of parameter binding methods - <Mvc:annotation-driven></Mvc:annotation-driven> <!--Configuring the Handler processor - <Beanclass= "Com.king.controller.UserController"></Bean> <!--Configuring the View resolver - <Beanclass= "Org.springframework.web.servlet.view.InternalResourceViewResolver"></Bean></Beans>
2. Modify the Usercontroller.java class as follows:
PackageCom.king.controller;Importjava.util.ArrayList;Importjava.util.Arrays;Importjava.util.List;ImportOrg.springframework.stereotype.Controller;Importorg.springframework.web.bind.annotation.RequestMapping;ImportOrg.springframework.web.servlet.ModelAndView;ImportCom.king.pojo.User; @Controller
Public classUsercontroller {@RequestMapping ("/getlist") PublicModelandview getList () {System.out.println ("Start Usercontroller"); List<User> list =NewArraylist<>(Arrays.aslist (NewUser (1, "Zhangsan", 20), NewUser (1, "Zhang2", 22), NewUser (1, "Zhang3", 23), NewUser (1, "zhang4s", 24) )); Modelandview MV=NewModelandview (); Mv.addobject ("List", list); Mv.setviewname ("Page/list.jsp"); returnMV; }}
The processor Mapper and processor adapter used in the "Springmvc notes" Lesson IV annotated