Introduction to SPRINGMVC Controller annotations

Source: Internet
Author: User

Spring2.5 before we did that by implementing Control interface or implementation to define our processor class.

Spring2.5 Note Processor support was introduced, @controller and the @requestMapping annotations Define our classes and provide a powerful set of annotations:

Need to pass processor mapping

defaultannotationhandlermapping and Processor adapters Annotationmethodhandleradapter to turn on support @Controller and @RequestMapping the annotated processor.

@ Controller used to identify the processor class

@RequestMapping: Mapping rules for request-to-processor functional methods;

@RequestParam: Bind the request parameter to the method parameter of the processor function processing method;

@ModelAttribute: The binding of the request parameter to the command object;

Spring3.0

use of a new handlermapping and the Handleradapter Support @Controller and the @RequestMapping Annotation Processor

the new @Contoller and @requestmapping annotation support classes: Processor mapping requestmappinghandlermapping

and Processor Adapters requestmappinghandleradapter combination to replace Spring2.5 processor mapping defaultannotationhandlermapping and processor adapter Annotationmethodhandleradapte R

Let's take a look at the basic annotations below

The mapping of the processors is assigned to the following

    1. URL Path mapping: Using URL mapping request to the processor's functional processing method;
    2. Request Method Mapping Qualification: If the Limit function processing method only handles GET request;
    3. Request Parameter Mapping Qualification: If the qualification only deals with " ABC "request parameter request;
    4. Request Header Mapping Qualification: If the limit is only processed " Accept=application/json "Request

implementation of the controller 1 defining the processor @Controller

@Controller///① to declare a Pojo class as processor @requestmapping ("/examqueryquestion")///② request URL-to-processor feature-handling method mapping public Classqueryquestioncontroller {}

1.1 Narrowing request mapping @RequestMapping

http://192.168.24.9:8080/ Itoo-exam-questionbankmanage-web / examqueryquestion / toquestiontypesexcel

@Controller // / ① will a POJO class is declared as a processor

@RequestMapping ("/examqueryquestion") // /Generic Request prefix

Public class Queryquestioncontroller {

@RequestMapping ("/toquestiontypesexcel")

Public Stringtoquestiontypesexcel (HttpServletRequest request,

HttpServletResponse Resposne) {

return "/examqueryquestion";

}

}

can be passed in a POJO Place on class @Controller or @RequestMapping , you can put a POJO class becomes processor;


2Spring configuration file spring-mvc.xml

<!--Spring3.1 start annotations handlermapping-<bean  

3 Configuration of the view parser

or use the previous Org.springframework.web.servlet.view.InternalResourceViewResolver .

4 configuration of the processor


simply register the processor implementation class with the spring configuration file, spring defaultannotationhandlermapping or requestmappinghandlermapping @Controller or Span lang= "en-US" style= "FONT-SIZE:18PX; Font-family:calibri "> @RequestMapping auto discovery.

Summary:

This content is A small part of Spring, its content is a simple injection method, no longer have the configuration file, Of course, the pre-learning configuration file Method injection is also the same , the basic understanding is not much what, simple record two ways of learning.

Introduction to SPRINGMVC Controller 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.