View parameter binding annotations and return value annotations from SPRINGMVC source

Source: Internet
Author: User

When using SPRINGMVC to provide annotations for method parameter bindings and method return value processing, such as sometimes 400 or 500 errors are reported, self-understanding of the use of annotations, but in some cases the extension of parameter binding more reasonable, And so on, we need to have a deep understanding of SPRINGMVC's internal implementation. In the error debugging, according to different annotations and return value types can drill down to SPRINGMVC specific implementation class source code for tracking to see, help us to use good springmvc.


1. The interface to parse the method parameters is handlermethodargumentresolver

Here are some specific implementation classes that implement different parsing binding capabilities for different annotations:

1. Requestparammethodargumentresolver

Support for parameters with @requestparam annotations or parameters with Multipartfile type

2. Requestparammapmethodargumentresolver

Support for parameters with @requestparam annotations && @RequestParam Annotation Properties value existence && parameter type is the attribute that implements the map interface

3. Pathvariablemethodargumentresolver

Supports parameters with @pathvariable annotations and if the parameter implements the map interface, the @PathVariable annotation takes the Value property

4. Matrixvariablemethodargumentresolver

Supports parameters with @matrixvariable annotations and if the parameter implements the map interface, the @MatrixVariable annotation takes the Value property

5. Requestresponsebodymethodprocessor

Resolve binding method parameters with @requestbody and method return values with @responsebody

6. Servletrequestmethodargumentresolver

parameter types are implementation or inheritance or WebRequest, ServletRequest, Multipartrequest, HttpSession, Principal, Locale, TimeZone, InputStream, Reader, HttpMethod these classes.

(This is why we add a httpservletrequest parameter in the controller's method, and spring will automatically get the reason for the HttpServletRequest object)

7. Servletresponsemethodargumentresolver

Parameter types are implementations or inheritance, or Servletresponse, OutputStream, writer, and the like

8. Redirectattributesmethodargumentresolver

parameter is a class that implements the Redirectattributes interface

9. Httpentitymethodprocessor

The parameter type is httpentity

From the name we also see that the end of the resolver is the implementation of the Handlermethodargumentresolver interface class, Ending with processor is the class that implements the Handlermethodargumentresolver and Handlermethodreturnvaluehandler.

2. Method return value Processing interface Handlermethodreturnvaluehandler

Here are some specific implementation classes that implement different functions for different annotations or return value types:

1. Modelandviewmethodreturnvaluehandler

The return value type is Modelandview or its subclasses

2. Modelmethodprocessor

The return value type is model or its subclass

3. Viewmethodreturnvaluehandler

The return value type is view or its subclass

4. Httpheadersreturnvaluehandler

The return value type is httpheaders or its subclasses

5. Modelattributemethodprocessor

return value has @modelattribute annotations

6. Viewnamemethodreturnvaluehandler

The return value is void or string


Reference from: http://www.cnblogs.com/fangjian0423/p/springMVC-request-param-analysis.html

View parameter binding annotations and return value annotations from SPRINGMVC source

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.