One, non-annotated processor mapper
1,org.springframework.web.servlet.handler.beannameurlhandlermapping
The bean configures the URL by name, as follows:
< Bean id="ItemsController1"name="/queryitems_test.action"class=" Cn.itcast.ssm.controller.ItemsController1 "/>
2,org.springframework.web.servlet.handler.simpleurlhandlermapping
Configure the URL in the following way:
<Bean class="Org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">< Property name="Mappings"><Props> <prop Key="/queryitem.action">ItemsController1</prop><prop Key="/queryitem2.action">Hellodemo</prop> </Props></ Property></Bean>
Second, non-annotated processor adapter
1,org.springframework.web.servlet.mvc.simplecontrollerhandleradapter
Requires handle to implement the Controller interface:
Public classItemsController1ImplementsController { PublicModelandview HandleRequest (httpservletrequest request,httpservletresponse response)throwsException {//Call service to find database, query commodity list, use static data simulation hereList<items> itemslist =NewArraylist<items> ();//Populating the list with static dataItems Items_1 =NewItems (); Items_1.setname ("Lenovo Notebook"); Items_1.setprice (6000f); 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);//Return to ModelandviewModelandview Modelandview =NewModelandview ();//equivalent to request setattribut, fetching data through Itemslist in JSP pagesModelandview.addobject ("itemslist", itemslist);//Specify ViewModelandview.setviewname ("/web-inf/jsp/items/itemslist.jsp");returnModelandview;}}
2,org.springframework.web.servlet.mvc.httprequesthandleradapter
The handler required to write implements the Httprequesthandler interface.
Public classItemsController2ImplementsHttprequesthandler { Public voidHandleRequest (httpservletrequest request,httpservletresponse response)throwsServletexception, IOException {//Call service to find database, query commodity list, use static data simulation hereList<items> itemslist =NewArraylist<items> ();//Populating the list with static dataItems Items_1 =NewItems (); Items_1.setname ("Lenovo Notebook"); Items_1.setprice (6000f); 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);//Set model dataRequest.setattribute ("itemslist", itemslist);//Set up a forwarded viewRequest.getrequestdispatcher ("/web-inf/jsp/items/itemslist.jsp"). Forward (request, response);//Use this method to set the data format of the response, such as in response to JSON data, by modifying the response/*response.setcharacterencoding ("Utf-8"); Response.setcontenttype ("Application/json;charset=utf-8"); Response.getwriter (). Write ("JSON string"); * /}}
Note: Multiple mappers and multiple adapters can coexist
Non-annotated processor adapters and processor mapper