关于用@pathvariable实现响应多个渠道的请求
2016-04-14 15:18
351 查看
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";
}
}
最好不要把动态参数放在类名上的requestMapping()中,这样就不够灵活,首先保证所有的请求都可以进来到类映射
@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";
}
}
最好不要把动态参数放在类名上的requestMapping()中,这样就不够灵活,首先保证所有的请求都可以进来到类映射
相关文章推荐
- 在 iOS 上开始创建你的虚拟现实应用
- Android的Message Pool是什么——源码角度分析
- shell运算
- C#委托与事件的本质区别
- 一个经典的单例模式(双重检查锁)
- osv kernel 内存初始化管理
- 【转】用Js的eval解析JSON中的注意点
- 最近在处理Cocoa NSString时, 遇到一些字符编码的问题
- ubunbu 12.04中安装xrdp建立远程桌面
- iOS开发系列--音频播放、录音、视频播放、拍照、视频录制
- NKWebView的简单使用
- [Magento SQL] 返回产品SKU,Stutus(上下架状态)和库存
- ActionInvocation的理解
- Windows 10 LNK File分析
- 【bzoj2834】【回家的路】【最短路】
- iOS label自适应宽度 左端对齐 自动换行
- Maven---入门
- ZZULIOJ-1876 礼上往来(全错位排列)
- 线程-001-线程简介
- 强化学习笔记1