SPRINGMVC03 non-annotated and annotated processor mapper and adapters

Source: Internet
Author: User
Tags lenovo

1 Other non-annotated processor mappers and adapters1. 1BeanNameUrlHandlerMapping (mapper) matches the name of the spring container bean according to the request URL (xxxx.action) to find the corresponding bean (program-written handler)1. 2SimpleUrlHandlerMapping (Mapper)<!--simple URL mapping, centrally configured bean ID corresponding to the URL--<beanclass="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="Mappings"> <props> <prop key="/itemstest1.action">itemController1</prop> <prop key="/itemstest2.action">itemController2</prop> </props> </property> </bean>Note: Multiple processor mappers are configured in Springmvc.xml, and multiple processor mappers can coexist. Which mapping succeeds is used. 1the. 3SimpleControllerHandlerAdapter (adapter) requires that the handler (Controller) written by the program need to implement the Controller interface. <!--Configuring the processor adapter, the SPRINGMVC framework determines whether the class is a processor adapter and <, based on the Handleradapter interfaceBeanclass="Org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/>1. 4HttpRequestHandlerAdapter (adapter) in Springmvc.xml configuration: Httprequesthandleradapter<!--httprequesthandleradapter Adaptor--<beanclass="Org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter"/>requires handler to implement Httprequesthandler interface1.4. 1 Development Handler Public classItemController2 implements Httprequesthandler {@Override Public voidHandleRequest (httpservletrequest request, httpservletresponse response) throws Servletexception, Ioexcepti on {//use static data to display a list of commodity information on a JSP page//Product ListList<items> itemslist =NewArraylist<items>(); Items Items_1=NewItems (); Items_1.setname ("Lenovo Notebook");        Items_1.setprice (6000F); Items_1.setcreatetime (NewDate ()); Items_1.setdetail ("ThinkPad T430 Lenovo notebook computer! "); Items items_2=NewItems (); Items_2.setname ("Apple Phone");        Items_2.setprice (5000F); Items_2.setdetail ("iphone6 Apple Phone! ");        Itemslist.add (Items_1);        Itemslist.add (items_2); Request.setattribute ("itemslist", itemslist); //forward to JSP pageRequest.getrequestdispatcher ("/web-inf/jsp/itemslist.jsp"). Forward (request, response); }}1.4. 2 Configuration Handler<!--handler2--<bean id="ItemController2" class="Cn.itcast.springmvc.first.ItemController2"></bean>using the Simple URL mapper:<!--simple URL mapping, centrally configured bean ID corresponding to the URL--<beanclass="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="Mappings"> <props> <prop key="/itemstest1.action">itemController1</prop> <prop key="/itemstest2.action">itemController2</prop> </props> </property> </bean>Mapper is based on the URL to find handler, when there are more than one mapper the same URL, all the mapper in a list queue, the map URL when the time taken from the collection, get the use, the back is no matter. 

SPRINGMVC03 non-annotated and annotated processor mapper and adapters

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.