首页 > 编程语言 > 详细

spring mvc中的@PathVariable

时间:2017-10-12 12:55:13      阅读:265      评论:0      收藏:0      [点我收藏+]

  spring mvc中的@PathVariable是用来获得请求url中的动态参数的,十分方便,复习下:

Java代码  技术分享
    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.      }  

spring mvc中的@PathVariable

原文:http://www.cnblogs.com/zhangtan/p/7655413.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!