spring mvc中的@PathVariable获得请求url中的动态参数

2025-05-29 0 75

spring mvc中的@PathVariable是用来获得请求url中的动态参数的,十分方便,复习下:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21
@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";

}

}

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持快网idc!

原文链接:http://www.cnblogs.com/Zyf2016/p/6376199.html

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 spring mvc中的@PathVariable获得请求url中的动态参数 https://www.kuaiidc.com/118827.html

相关文章

发表评论
暂无评论