spring mvc中的@PathVariable
2015-07-27 20:12
531 查看
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"; } }
相关文章推荐
- 深入理解JAVA虚拟机笔记-05
- eclipse创建maven管理的web项目
- 【转】java中的TreeMap与TreeSet关系及实现(红黑树)
- 二叉树的三种排序Java实现
- java中的异常
- 你的Java日志,有没有用这些改进办法
- JAVA学习第十天
- Java调用存储过程返回数组
- JAVA 并发编程-线程池(七)
- 重学java23种设计模式(5)单例模式
- JAVA操作LDAP总结
- 《深入浅出struts2》--第八章,输入验证-内建验证程序required,requiredstring和stringlength
- SSH学习一 STRUTS2 DTO
- java入门相关
- spring中@value注解需要注意
- 重学java23种设计模式(4)原型模式
- java.lang.NumberFormatException: empty String
- 《深入浅出struts2》--第七章,类型转换-支持与Map一起使用
- poj 1001 java大精度
- java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String