@RequestMapping define different processor mapping rules

Source: Internet
Author: User

  

The @requestmapping annotations allow you to define different processor mapping rules.

1. URL Path Mapping

@RequestMapping (value= "item") or @requestmapping ("/item")

Value is an array, you can map multiple URLs to the same method

/*** Check Product List *@return */@RequestMapping (Value= {"ItemList", "Itemlistall" }) PublicModelandview queryitemlist () {//Check Product dataList<Item> list = This. Itemservice.queryitemlist (); //Create Modelandview, set logical view nameModelandview MV=NewModelandview ("ItemList"); //Put the product data in the modelMv.addobject ("ItemList", list); returnMV;}

2. Add to Class

Add @requestmapping (URL) on class to specify a generic request prefix, limiting all method request URLs under this class must start with the request prefix

You can use this method to classify URLs, such as:

The request URL that needs to enter the Queryitemlist () method At this point is:

Http://127.0.0.1:8080/springmvc-web2/item/itemList.action

Or

Http://127.0.0.1:8080/springmvc-web2/item/itemListAll.action

3. Request Method Qualification

In addition to the URL can be set, you can also qualify the request in the method

    • Restrict Get methods
@RequestMapping (method = Requestmethod.get)

If you access via post, the error is:

HTTP Status 405-request method ' POST ' not supported

For example:

@RequestMapping (value = "ItemList", method = Requestmethod.post)

    • Limit Post method
@RequestMapping (method = Requestmethod.post)

If get access then error:

HTTP Status 405-request method ' GET ' not supported

    • Both get and post can
@RequestMapping (method = {Requestmethod.get,requestmethod.post})

@RequestMapping define different processor mapping rules

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.