Springmvc learning notes (3)-annotation processor mappers and adapters

Source: Internet
Author: User

Springmvc learning notes (3)-annotation processor mappers and adapters
Springmvc learning notes (3)-annotation processor mappers and adapters

This article mainly introduces the annotation processor er and adapter Configuration

Load by default

Front-end controller from\org\springframework\web\servlet\DispatcherServlet.propertiesContains components such as the processor er, adapter, and view parser. If not configured in springmvc. xml, the default loaded

Annotation processor er and adapter

Used before spring3.1 org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMappingAnnotation er. Use after spring3.1 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMappingAnnotation er. Used before spring3.1 org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapterAnnotation adapter. Use after spring3.1 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapterAnnotation adapter annotation processor er and adapter
<code class="language-xml hljs "><!--{cke_protected}{C}%3C!%2D%2D%20%E6%B3%A8%E8%A7%A3%E7%9A%84%E6%98%A0%E5%B0%84%E5%99%A8%20%2D%2D%3E-->    <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"><!--{cke_protected}{C}%3C!%2D%2D%20%E6%B3%A8%E8%A7%A3%E7%9A%84%E9%80%82%E9%85%8D%E5%99%A8%20%2D%2D%3E-->    <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"></bean></bean></code>

Or

<code class="language-xml hljs ">    <!--{cke_protected}{C}%3C!%2D%2D%20%E4%BD%BF%E7%94%A8mvc%3Aannotation-driven%E4%BB%A3%E6%9B%BF%E4%B8%8A%E9%9D%A2%E4%B8%A4%E4%B8%AA%E6%B3%A8%E8%A7%A3%E6%98%A0%E5%B0%84%E5%99%A8%E5%92%8C%E6%B3%A8%E8%A7%A3%E9%80%82%E9%85%8D%E7%9A%84%E9%85%8D%E7%BD%AE%0A%20%20%20%20%20mvc%3Aannotation-driven%E9%BB%98%E8%AE%A4%E5%8A%A0%E8%BD%BD%E5%BE%88%E5%A4%9A%E7%9A%84%E5%8F%82%E6%95%B0%E7%BB%91%E5%AE%9A%E6%96%B9%E6%B3%95%EF%BC%8C%0A%20%20%20%20%20%E6%AF%94%E5%A6%82json%E8%BD%AC%E6%8D%A2%E8%A7%A3%E6%9E%90%E5%99%A8%E9%BB%98%E8%AE%A4%E5%8A%A0%E8%BD%BD%E4%BA%86%EF%BC%8C%E5%A6%82%E6%9E%9C%E4%BD%BF%E7%94%A8mvc%3Aannotation-driven%E5%88%99%E4%B8%8D%E7%94%A8%E9%85%8D%E7%BD%AE%E4%B8%8A%E9%9D%A2%E7%9A%84RequestMappingHandlerMapping%E5%92%8CRequestMappingHandlerAdapter%0A%20%20%20%20%20%E5%AE%9E%E9%99%85%E5%BC%80%E5%8F%91%E6%97%B6%E4%BD%BF%E7%94%A8mvc%3Aannotation-driven%0A%20%20%20%20%20%2D%2D%3E-->   </code>
Development annotation Handler

Use the annotator and annotation adapter. (The annotator and annotation adapter must be paired)

// Use @ Controller to identify it as a Controller @ Controllerpublic class ItemsController3 {// product query list @ RequestMapping ("/queryItems") // ing the queryItems method and url, A method corresponds to a url // It is generally recommended to write the url and method as public ModelAndView queryItems () throws Exception {// call the service to find the database and query the product List. Here, the static data is used to simulate the List.
  
   
ItemsList = new ArrayList
   
    
(); // Fill the static data in the list with Items items_1 = new Items (); items_1.setName ("Lenovo notebook"); items_1.setPrice (6000f ); items_1.setDetail ("ThinkPad T430 c3 Lenovo laptop! "); Items items_2 = new Items (); items_2.setName (" Apple phone "); items_2.setPrice (5000f); items_2.setDetail (" iPhone 6 Apple phone! "); ItemsList. add (items_1); itemsList. add (items_2); // return ModelAndView modelAndView = new ModelAndView (); // It is equivalent to the setAttribute method of the request. You can use itemsList to retrieve data modelAndView on the jsp page. addObject ("itemsList", itemsList); // specify the modelAndView. setViewName ("/WEB-INF/jsp/items/itemsList. jsp "); return modelAndView ;}}
   
  
Load Handler in spring container
<code class="language-xml hljs "><!--{cke_protected}{C}%3C!%2D%2D%20%E5%AF%B9%E4%BA%8E%E6%B3%A8%E8%A7%A3%E7%9A%84Handler%20%E5%8F%AF%E4%BB%A5%E5%8D%95%E4%B8%AA%E9%85%8D%E7%BD%AE%0A%20%20%20%20%E5%AE%9E%E9%99%85%E5%BC%80%E5%8F%91%E4%B8%AD%E5%8A%A0%E4%BD%A0%E4%BD%BF%E7%94%A8%E7%BB%84%E4%BB%B6%E6%89%AB%E6%8F%8F%0A%20%20%20%20%2D%2D%3E-->    <!--{cke_protected}{C}%3C!%2D%2D%20%20%3Cbean%20%20class%3D%22com.iot.ssm.controller.ItemsController3%22%2F%3E%20%2D%2D%3E-->    <!--{cke_protected}{C}%3C!%2D%2D%20%E5%8F%AF%E4%BB%A5%E6%89%AB%E6%8F%8Fcontroller%E3%80%81service%E3%80%81...%0A%20%20%20%20%E8%BF%99%E9%87%8C%E8%AE%A9%E6%89%AB%E6%8F%8Fcontroller%EF%BC%8C%E6%8C%87%E5%AE%9Acontroller%E7%9A%84%E5%8C%85%0A%20%20%20%20%20%2D%2D%3E-->    <context:component-scan base-package="com.iot.ssm.controller"></context:component-scan></code>

Related Article

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.