Spring MVC HTTP Request address Mapping (iii)

Source: Internet
Author: User

The Spring MVC framework maps the methods of @requestmapping in a class with @controller by scanning and then calls the mapped method to process the request, which is handled by the Dispaterservlet by default.

HTTP request Mapping principle

  

the basis for which Spring MVC maps

URL-qualified: URL expression

Spring MVC's address mapping supports standard URLs, while default support is Ant-style URLs. Gca

URL Description
/account/*/create Match URLs such as/account/aaa/create,/account/bbb/create, etc.
/account/**/create Match URLs such as/account/create,/account/aaa/bbb/create, etc.
/account/create?? Match URLs such as/ACCOUNT/CREATEAA,/account/createbb, etc.
/account/{accountid} Match URLs such as account/123, ACCOUNT/ABC, etc.
/account/**/{userid} Match URLs such as account/aaa/bbb/123, account/aaa/456, etc.
Account/{accountid}/customer/{customerid}/detail URLs that match account/1234/customer/0000/detail, etc.
URL-qualified: The value of {XXX} in the binding path

  

@RequestMapping ("/{accountid}")    public Modelandview showdetail (@PathVariable ("AccountId" String accountId) {        modelandview mavnew  Modelandview ();        Mav.setviewname ("User/showdetail");        Mav.addobject ("user", Userservice.getuserbyid (userId));     return Mav;}

The {XXX} placeholder in the URL can be bound to the entry of an action method by @pathvariable ("xxx").

In the 3. X if @pathvariable does not specify a parameter name, it is only possible to open the debug switch (javac-debug=no) at compile time!! (not recommended), it seems that 4.x does not have this problem.

Spring MVC HTTP Request address Mapping (iii)

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.