SPRINGMVC GET request and its request address notation

Source: Internet
Author: User

Today, you need to write an interface, after writing, testing the line has been reported 404 errors, do not know why the error. Should be a GET request address problem, GET request has two parameters, the time to change to a parameter is good, perhaps that way is not suitable for writing two parameters of Get request it.

Mode one: GET request a parameter

@RequestMapping ("/testpathvariable/{id}") public String testpathvariable (@PathVariable (value= " ID ") Integer ID) {    System.out.println (" testpathvariable: "+ ID);     return        SUCCESS;} 

URL Request Address: http://localhost:8080/testPathVariable/001

Page output: testpatvariable:001

Mode two: Get request multiple parameters (2)

@RequestMapping (value= "/testrequestparam") Public
@RequestParam (value= "age", required=falseint -age ) { System.out.println (" Testrequestparam "+" Username: "+ username +" Age: "+ age); return SUCCESS;}

URL Request Address: http://localhost:8080/testRequestParam?username=jackie&age=12

Page output: Teatrequestparam username:jackie age:12

Spring annotations

1. How spring MVC matches the request path

@RequestMapping are used to map requests, such as GET requests, post requests, or restful and non-restful styles.

This annotation can be used on a class or on a method, if used on a class, to represent the parent path of all methods in that class.

2. How spring MVC gets the requested parameters

@PathVariable This annotation is used to map placeholders for bindings in the request URL. By @pathvariable, you can bind the parameters of placeholders in URLs to the arguments of the controller processing method.

@RequestParam The annotation is also used to get the request parameters.

    

SPRINGMVC GET request and its request address notation

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.