spring mvc中的@PathVariable

来源:互联网 发布:博雅软件上市吗 编辑:程序博客网 时间:2024/06/02 03:31

spring mvc中的@PathVariable是用来获得请求url中的动态参数的

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

(原文链接:http://jackyrong.iteye.com/blog/2059307)

0 0
原创粉丝点击