Use the @RequestMapping to parse the parameters in the HTTP request.
1 a GET request with parameters is sent through the browser to access the services on the server.
http://localhost:8080/springmvc/RequestParam/testRequestParam2?username=xiaoming&age=11
The URL describes a GET request domain name of SPRINGMVC, the backend is a controller mapping requestparam,testrequestparam2 is a map of the published service name, and the corresponding request parameters and parameter values after the question mark
2 interface of the service side
ImportOrg.springframework.stereotype.Controller;Importorg.springframework.web.bind.annotation.RequestMapping;ImportOrg.springframework.web.bind.annotation.RequestMethod;ImportOrg.springframework.web.bind.annotation.RequestParam, @Controller @requestmapping ("/requestparam") Public classRequestparamsservice { Public Final StaticString succeedd= "Show"; /**Requestparam * Mapped request parameters can be multiple parameters * required * Indicates whether the parameter is required by default is True (indicates is required) * DefaultValue * The default value of the request parameter * *@paramusername *@paramAge *@return */@RequestMapping (Value= "/testrequestparam1", method=requestmethod.get) PublicString testRequestParam1 (@RequestParam (value= "username") string username, @RequestParam (value= "age", required=false, defaultvalue= "0")intAge ) {System.out.println ("TestRequestParam1 username=" +username + ", age=" +Age ); returnSucceedd; } /*** URL: *@paramusername *@paramAge *@return */@RequestMapping (Value= "/testrequestparam2", method=requestmethod.get) PublicString TestRequestParam2 (@RequestParam (value= "username") string username, @RequestParam (value= "age", required=false) (Integer age) {System.out.println ("TestRequestParam2 username=" +username + ", age=" +Age ); returnSucceedd; } }
3 Testing through the browser
about how request parameters for SPRINGMVC are handled (@RequestMapping to map request parameters)