spring mvc中的@PathVariable获得请求url中的动态参数
作者:伴我前行 时间:2023-08-22 22:08:40
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";
}
}
来源:http://www.cnblogs.com/Zyf2016/p/6376199.html
标签:spring,mvc,参数
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Android 自定义View实现芝麻分曲线图效果
2022-11-22 01:59:13
![](https://img.aspxhome.com/file/2023/3/138873_0s.png)
使用IDEA搭建ssm框架的详细图文教程
2021-12-04 10:37:20
![](https://img.aspxhome.com/file/2023/4/94744_0s.jpg)
详解Spring缓存注解@Cacheable,@CachePut , @CacheEvict使用
2021-11-18 12:18:05
C# DateTime.ToString根据不同语言生成相应的时间格式
2022-04-16 12:34:51
![](https://img.aspxhome.com/file/2023/4/113774_0s.png)
mall整合SpringTask实现定时任务的方法示例
2023-09-15 18:08:08
Dwr3.0纯注解(纯Java Code配置)配置与应用浅析二之前端调用后端
2023-08-19 17:32:33
![](https://img.aspxhome.com/file/2023/3/57693_0s.png)
Eclipse下编写java程序突然不会自动生成R.java文件和包的解决办法
2023-11-19 00:24:05
SpringMVC上传和解析Excel方法
2022-02-23 21:02:11
![](https://img.aspxhome.com/file/2023/0/116170_0s.jpg)
JAVA 获取系统当前时间实例代码
2022-09-01 05:53:01
Android实现数字跳动效果的TextView方法示例
2023-05-24 16:54:29
![](https://img.aspxhome.com/file/2023/4/137784_0s.gif)
Android IPC机制Messenger实例详解
2023-04-27 13:25:06
Java之操作Redis案例讲解
2023-06-18 03:48:41
![](https://img.aspxhome.com/file/2023/8/61288_0s.png)
什么是Java自旋锁
2022-09-22 22:10:55
![](https://img.aspxhome.com/file/2023/1/72301_0s.png)
Android实现自定义圆形进度条
2022-10-28 04:55:22
![](https://img.aspxhome.com/file/2023/2/92602_0s.jpg)
java中如何判断JSONObject是否存在某个Key
2022-06-10 15:07:24
![](https://img.aspxhome.com/file/2023/8/119148_0s.png)
SpringBoot通过@Value实现给静态变量注入值详解
2022-04-30 14:30:37
mybatis 运行时加载自定义mapper文件方式
2023-08-16 10:00:16
![](https://img.aspxhome.com/file/2023/7/132057_0s.jpg)
关于eclipse安装spring插件报错An error occurred while collecting items to be installed...解决方案
2023-05-27 03:34:45
![](https://img.aspxhome.com/file/2023/1/78351_0s.png)
SpringBoot整合TomCat实现本地图片服务器代码解析
2021-07-30 16:34:19
Android实现Banner界面广告图片循环轮播(包括实现手动滑动循环)
2022-02-06 17:05:35
![](https://img.aspxhome.com/file/2023/1/93261_0s.gif)