Optional parameters for @requesMapping configurable parameters and label handling methods

Source: Internet
Author: User
Tags locale

The processing functions that use the @requesmapping callout include optional parameters, in addition to HttpServletRequest, HttpServletResponse, HttpSession the parameters that are common in these Web applications, as well as the previously mentioned @pathvariable, can include the following optional parameters, where the order of most of the parameters is not specifically required. Java.util.Locale the locale to which the current request belongs. Java.io.InputStream or java.io.Reader used to read the request content, equivalent to Request.getinputstream () or request.getreader (); Java.io.OutputStream or java.io.Writer is used to generate reponse content, which is equivalent to Response.getoutputstream () or Response.getwriter (). Java.security.Principal an object that is currently authenticated by a user WebRequest or nativewebrequestspring to a Web element such as Request,response,session The MAP structure used by JAVA.UTIL.MAP or Org.springframework.ui.Model or ORG.SPRINGFRAMEWORK.UI.MODELMAP to store the domain model. Httpentity<?>can be used to read the header and body contents of the HTTP request, note that because httpentity, @RequestBody, reader these three types of parameters are inputstram to read httpbody data, The InputStream stream cannot be read over and over again, so these three types of parameters cannot be used together. And without setting the content-type or if no corresponding Messageconverter is set, an error will be given. Command or form objects automatically converts the parameters in the request requests to the corresponding Java bean instance through the spring databinding mechanism. Errors or bindingresult the check result of the command or form objects value. This parameter must be immediately following the command or form object parameter that you want to verify. Because databinding can allow input parameters to be bound to multiple Java beans (that is, we can convert the input request param into multiple Java objects). The state of the sessionstatussession. When the @sessionattributes is used to label the request with the corresponding value in the session, the Sessionstatus is used at the end of processing. SetComplete () to set the session to aging. @RequestParam bind the request parameter with the handler method parameter. For example, @requestparam (value= "username", defaultvalue= "WinZip", required=falseThe String name indicates that the username parameter in the request is bound to the name parameter in the handler method, and the default value is "WinZip", which can be passed without this parameter @ Requestheader binds the parameter in handler method to the value in the request header, such as @requestheader (required=false, value= "User-agent"A String UA indicates that the header of the"User-agent"with the UA this entry is bound. @RequestBody bind the parameter in handler method to the value in the request context body, such as @requestbody String U, to bind the contents of the request body with the U-entry parameter. @CookieValue bind a parameter in handler method to a value in a cookie such as @cookievalue (value= "Jsessionid", required=falseString Jssionid @ModelAttribute binds the argument in handler method to the corresponding type, the name defaults to the class name (lowercase first letter), and if the value is specified by Modelattribute, the value is used as the model Attribute name. such as @modelattribute ("Ooxx"User U creates a model attribute with a key value of Ooxx in Modelmap. @ModelAttribute user U or user u creates a model attribute with a key value of user in Modelmap

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.