SPRINGMVC--@RequestParam annotations (background controller get parameters)

Source: Internet
Author: User

There are two main ways to get the parameters in the Springmvc background control layer, one is Request.getparameter ("name") and the other is obtained directly with the annotation @requestparam.

1. Get the submitted parameters:

@RequestMapping ("Testrequestparam") public      String filesupload (@RequestParam string inputstr, HttpServletRequest Request) {  System.out.println (inputstr); int inputint = integer.valueof (Request.getparameter ("Inputint")); System.out.println (inputint);//... Omit return "index";    }   
Spring is automatically encapsulated in the name of the parameter, and we can use the parameter name directly.

2. Other uses:

Pass in the specified parameter name

@RequestParam string inputstr//To specify the incoming parameter as AA, if the front end does not pass AA parameter name, will error @requestparam (value= "AA") String Inputstr

Required=false or true can be used to require the @requestparam configuration of the front-end parameters must be transmitted

Required=false indicates that the argument will be assigned a value of null,required=true is required to have @requestmapping ("Testrequestparam") public      String Filesupload (@RequestParam (value= "AA", Required=true) String inputstr, httpservletrequest request)
if the parameter annotated with @requestmapping is an int primitive type, but required=false, then if the parameter value is not passed the error, because does not pass the value, will assign the value to be null to int, this time needs to use the packing type (integer);

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

SPRINGMVC [email protected] annotations (background controller get parameters)

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.