An MVC application based on annotation configuration

Source: Internet
Author: User

1. requestmapping Annotation Application

@RequestMapping can be used on class definitions and method definitions

@RequestMapping indicate which customer request this class or method corresponds to

Turn on the @requestmapping annotation map, Need to define the requestmappinghandlermapping (before class definition) and Requestmappinghandleradapter (before the method definition) two bean components in the spring XML configuration file

Tips:

Defaultannotationhandlermapping and Annotationmethodhandleradapter two components need to be defined before Spring3.1 version

Requestmappinghandlermapping and requestmappinghandleradapter Two bean component definition examples

 <!-- requestmappinghandlermapping  -->  bean  class  = " Org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping "  />  <!--  -->   bean  class  = "Org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"  />  

Starting with the Spring3.2 version, you can use the following XML configuration to simplify the requestmappinghandlermapping and Requestmappinghandleradapter definitions

</>

2. Controller annotation Application

It is recommended to declare the controller component using the @controller annotation, which makes the controller definition more flexible, without implementing the Controller interface, and the method of request processing can be flexibly defined

@Controller

For the @controller annotation to take effect, the component scan definition needs to be turned on in the spring XML configuration file, and the package containing the controller component is specified

<!-- opening @controller Annotations  - <  base-package= "Com.tarena.controller"/>

MVC apps based on annotation configuration

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.