In the second lesson example, the first processor mapper and processor adapter are configured in Springmvc.xml, as shown below.
<!--configuration of the first processor mapper beannameurlhandlermapping - <Beanclass= "Org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"></Bean> <!--Configure the first processor adapter Simplecontrollerhandleradapter - <Beanclass= "Org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"></Bean>
Next is the second processor mapper and processor adapter.
<!--configuration of the second processor mapper simpleurlhandlermapping - <Beanclass= "Org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> < Propertyname= "Mappings"> <Props> <propKey= "/getlist2.action">Usercontroller</prop> <propKey= "/getlist3.action">Usercontroller</prop> <propKey= "/getlist4.action">User2controller</prop> </Props> </ Property> </Bean> <!--Configure the second processor adapter Simplecontrollerhandleradapter - <Beanclass= "Org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter"></Bean>
The complete springmvc.xml is as follows:
Note: SPRINGMVC allows multiple mappers and multiple adapters to coexist, and does not affect each other, we use only one.
<?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 "> <!--Configuring the Handler processor - <BeanID= "Usercontroller"name= "/getlist.action"class= "Com.king.controller.UserController"></Bean> <BeanID= "User2controller"class= "Com.king.controller.User2Controller"></Bean> <!--configuration of the first processor mapper beannameurlhandlermapping - <Beanclass= "Org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"></Bean> <!--configuration of the second processor mapper simpleurlhandlermapping - <Beanclass= "Org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> < Propertyname= "Mappings"> <Props> <propKey= "/getlist2.action">Usercontroller</prop> <propKey= "/getlist3.action">Usercontroller</prop> <propKey= "/getlist4.action">User2controller</prop> </Props> </ Property> </Bean> <!--Configure the first processor adapter Simplecontrollerhandleradapter - <Beanclass= "Org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"></Bean> <!--Configure the second processor adapter Simplecontrollerhandleradapter - <Beanclass= "Org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter"></Bean> <!--Configuring the View resolver - <Beanclass= "Org.springframework.web.servlet.view.InternalResourceViewResolver"></Bean> </Beans>
At the same time, due to different adapters, the corresponding controller implementation of the interface is not the same, the second kind of user2controller is defined as follows:
The return to JSP page here is somewhat similar to struts2.
PackageCom.king.controller;Importjava.io.IOException;Importjava.util.ArrayList;Importjava.util.Arrays;Importjava.util.List;Importjavax.servlet.ServletException;Importjavax.servlet.http.HttpServletRequest;ImportJavax.servlet.http.HttpServletResponse;ImportOrg.springframework.web.HttpRequestHandler;ImportCom.king.pojo.User; Public classUser2controllerImplementshttprequesthandler{@Override Public voidHandleRequest (httpservletrequest request, httpservletresponse response)throwsservletexception, IOException {System.out.println ("Start User2controller"); List<User> list =NewArraylist<>(Arrays.aslist (NewUser (1, "Zhangsan", 20), NewUser (1, "Zhang2", 22), NewUser (1, "Zhang3", 23), NewUser (1, "zhang4s", 24) )); Request.setattribute ("List", list); Request.getrequestdispatcher ("Page/list.jsp"). Forward (request, response); }}
After you run Tomcat, enter getlist.action,getlist2.action,getlist3.actioin,getlist4.action in the URL to execute the query results.
One of Getlist.action, the first mapper, the first adapter
Getlist2.action + getlist3.action, the second mapper, the first type of adapter
Getlist4.action Second Mapper, second adapter
"Springmvc Notes" lesson three processor Mapper + processor Adapter