@ PathVariable and mvc @ pathvariable in spring mvc

Source: Internet
Author: User

@ PathVariable and mvc @ pathvariable in spring mvc

@ PathVariable in spring mvc is used to obtain dynamic parameters in the request url, which is very convenient. Review:

Java code
    1. @ Controller
    2. Public class TestController {
    3. @ RequestMapping (value = "/user/{userId}/roles/{roleId}", method = RequestMethod. GET)
    4. Public String getLogin (@ PathVariable ("userId") String userId,
    5. @ PathVariable ("roleId") String roleId ){
    6. System. out. println ("User Id:" + userId );
    7. System. out. println ("Role Id:" + roleId );
    8. Return "hello ";
    9. }
    10. @ RequestMapping (value = "/product/{productId}", method = RequestMethod. GET)
    11. Public String getProduct (@ PathVariable ("productId") String productId ){
    12. System. out. println ("Product Id:" + productId );
    13. Return "hello ";
    14. }
    15. @ RequestMapping (value = "/javabeat/{regexp1: [a-z-] + }",
    16. Method = RequestMethod. GET)
    17. Public String getRegExp (@ PathVariable ("regexp1") String regexp1 ){
    18. System. out. println ("URI Part 1:" + regexp1 );
    19. Return "hello ";
    20. }
    21. }

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.