博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
spring mvc中的@PathVariable
阅读量:4650 次
发布时间:2019-06-09

本文共 865 字,大约阅读时间需要 2 分钟。

 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.      }  
    21. }  

转载于:https://www.cnblogs.com/Zyf2016/p/6376199.html

你可能感兴趣的文章
Git详解之四:服务器上的Git
查看>>
[NOIP2002]矩形覆盖
查看>>
JavaScript 复杂判断的更优雅写法借鉴
查看>>
hdu 5186 zhx's submissions
查看>>
<mvc:annotation-driven/>浅析
查看>>
ArcEngine开发之自定义工具
查看>>
SQL视频总结
查看>>
P4878 道路修建-美国
查看>>
dp练习
查看>>
vim
查看>>
苹果电脑包管理
查看>>
maze_travel的隐私声明
查看>>
对正则表达式又重新学了一遍,笔记方便以后查阅
查看>>
NSArray和NSString的联合使用
查看>>
UIKit应用 - Swift 版本: 3.让UITableViewCell的背景色渐变
查看>>
Java反射
查看>>
building tool
查看>>
JS中for循环输出三角形
查看>>
字节对齐2
查看>>
kafka幂等producer
查看>>