The requestmapping of Spring MVC

Source: Internet
Author: User

1. Requestmapping
Requestmapping have class-level and method-level two levels, which contain properties that are value,method,consumes,produces
Value indicates the URL address to respond to.
Method that represents the response request

2.Uri Template

When commenting on requestmapping, you can set its value to correspond to the requested address to be processed. Here you can use a URI template to make the method respond to the request address of the template.


2.1 URI Template variable:
For example:/user/{userid},userid is a variable.
Parameters in the method in which they are mapped can get the value of the parameter with @pathvariable
@RequestMapping ("/user/zhangsan")
public void GetUserId (@RequestMapping String userid)
{
The parameter Useridd value is Zhangsan.
}

2.2 Using regular expressions in URI template variables
@RequestMapping ("/user/{userid:^lkj\\d\\d}")//kk request processing method only handles the UserID's value matching "lkj\\d\\d" request
public void KK (@PathVariable user)

The requestmapping of Spring MVC

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.