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" ; } } |
以上就是本文的全部內容,希望本文的內容對大家的學習或者工作能帶來一定的幫助,同時也希望多多支持服務器之家!
原文鏈接:http://www.cnblogs.com/Zyf2016/p/6376199.html