@ 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
- @ Controller
- Public class TestController {
- @ RequestMapping (value = "/user/{userId}/roles/{roleId}", method = RequestMethod. GET)
- Public String getLogin (@ PathVariable ("userId") String userId,
- @ PathVariable ("roleId") String roleId ){
- System. out. println ("User Id:" + userId );
- System. out. println ("Role Id:" + roleId );
- Return "hello ";
- }
- @ RequestMapping (value = "/product/{productId}", method = RequestMethod. GET)
- Public String getProduct (@ PathVariable ("productId") String productId ){
- System. out. println ("Product Id:" + productId );
- Return "hello ";
- }
- @ RequestMapping (value = "/javabeat/{regexp1: [a-z-] + }",
- Method = RequestMethod. GET)
- Public String getRegExp (@ PathVariable ("regexp1") String regexp1 ){
- System. out. println ("URI Part 1:" + regexp1 );
- Return "hello ";
- }
- }