@PathVariable in spring mvc gets the dynamic parameters in the request url

  • 2020-06-03 06:41:10
  • OfStack

The @PathVariable in spring mvc is used to obtain the dynamic parameters in request url, 10 points is convenient, please review:


 @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"; 
   } 
} 

Related articles: