The corresponding problems of Url-patter and @RequestMapping in SPRINGMVC

Source: Internet
Author: User

principle Brief

In the background, the full URL is matched, trimmed, removed <url-pattern> specified context part, remainder URL ', and then annotated @ by the SPRINGMVC response to the request initiated by the front-end. Requestmapping go to the Controller specific method and perform the specific processing.

give me a chestnut .

Full URL of the front-end request:

Http://localhost:8088/aaa/bbb/ccc?myParam=myValue

The URL format specified by the servlet:

<url-pattern>/aaa/*</url-pattern>

The correct configuration for the @RequestMapping is:

@RequestMapping (value= "/BBB/CCC") public
String demomethodsignature (string myparam) {/*method code*/}
If requestmapping= "/AAA/BBB/CCC", the equivalent full URL is:

Http://localhost:8088/aaa/aaa/bbb/ccc?myParam=myValue
Instead of wishing (forced access will show 404 pages)

Http://localhost:8088/aaa/bbb/ccc?myParam=myValue

It can be seen that the value of the annotation @RequestMapping is the result of the "narrow treatment" after <url-pattern>, and the excluded part

Http://localhost:8088/aaa
= http://localhost:8088 +/aaa
= Request Domain name default root path + <url-pattern> explicitly declared path

Conversely, if the annotation @RequestMapping value is "/x/y/z",<url-pattern> specified as "/aaa/*", the equivalent complete URL to the Controller method is accessed:

http://localhost:8088/aaa/x/y/z
=http://localhost:8088 +/aaa +/x/y/x
= domain name root path + <url-pattern> explicitly declared path + @ Requestmapping value

Reference articles:

1, Spring MVC Url-pattern and @requestmapping mapping small problem: http://blog.csdn.net/fangchao3652/article/details/54693814
2, the servlet url-pattern matching rules detailed description: https://www.cnblogs.com/51kata/p/5152400.html







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.