spring mvc中的@PathVariable
2016-04-16 12:00
621 查看
spring mvc中的@PathVariable是用来获得请求url中的动态参数的,十分方便,复习下:
Java代码
@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";
}
}
Java代码
@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";
}
}
相关文章推荐
- eclipse aidl.exe error while creating directories
- 一个Java音乐播放器
- 位运算符详细总结
- 一个求迷宫入口到出口最近距离的程序 JAVA版本
- Struts2 入门学习笔记(四)——输入校验
- JavaWeb系列之八(Cookie&Session)
- Spring中的AOP理解
- java.lang.IllegalStateException: This Activity already has an action bar supplied by the window deco
- Java提高篇(三三)-----Map总结
- Java项目源码学习笔记(一):IdentityCache
- 20145231《Java程序设计》第二次实验报告
- 一个随时间不断变化的值确认其变化范围的方法
- Java classpath and directories
- Java开发中的23种设计模式详解(转)
- Java多线程学习
- java之路径分隔符介绍
- Java线程创建和启动
- java.net.UnknownHostException
- [转载]java正则表达式
- java基础---静态变量、静态块、非静态块、构造函数及静态方法总结及一点儿想法