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)