软件编程
位置:首页>> 软件编程>> java编程>> spring mvc中的@PathVariable获得请求url中的动态参数

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

作者:伴我前行  发布时间:2023-08-22 22:08:40 

标签:spring,mvc,参数

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

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com