Processor Mapper and adapter for annotations

Source: Internet
Author: User
Tags lenovo

1. Configure the note Mapper and adapter.

<!--annotation mapper -- < Bean class="Org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" /> <!--Note Adapter -- < Bean class="Org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter" />

However, in the actual development, the annotations of the adapter and mapper configuration is often used to note-driven:

Using Mvc:annotation-driven instead of the top annotation mapper and annotation adapter configuration
Mvc:annotation-driven loads a number of parameter binding methods by default,
For example, the JSON conversion parser is loaded by default, if you use Mvc:annotation-driven do not configure the upper requestmappinghandlermapping and Requestmappinghandleradapter
Use Mvc:annotation-driven during actual development

2, Development Note handler

Adapters that use the callout's mapper and annotations (the annotated mapper and annotations must be paired with the adapter).

 PackageCn.itcast.ssm.controller;ImportJava.util.ArrayList;ImportJava.util.List;ImportOrg.springframework.stereotype.Controller;Importorg.springframework.web.bind.annotation.RequestMapping;ImportOrg.springframework.web.servlet.ModelAndView;ImportCn.itcast.ssm.po.Items;/** * @author Administrator * */@Controller Public classItemsController3 {//Commodity query list//@RequestMapping Implement mapping of Queryitems methods and URLs, one method corresponds to a URL//General recommendation to write URLs and methods as@RequestMapping ("/queryitems") PublicModelandview Queryitems ()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 View///Bottom path, if you configure the prefix of the JSP path in the view parser and the suffix of the JSP path, modify to//modelandview.setviewname ("/web-inf/jsp/items/itemslist.jsp");//upper path configuration can not specify JSP path prefix and JSP path suffix in the programModelandview.setviewname ("/web-inf/jsp/items/itemslist.jsp");returnModelandview;}}

3, load handler in spring container

For annotations, the handler can be configured individually, and it is recommended to use component scanning for automatic scanning in real development.

<bean class= "Cn.itcast.ssm.controller.ItemsController3"/>

<!--can scan controller, service 、...

Here, let's scan the controller, specify the controller's package.

-

< context:component-scanbase-package ="Cn.itcast.ssm.controller"  ></context:component-scan>

Processor Mapper and adapter for annotations

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.