Non-annotated processor adapter and processor Mapper

Source: Internet
Author: User

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

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.