about how request parameters for SPRINGMVC are handled (@RequestMapping to map request parameters)

Source: Internet
Author: User

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)

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.