@PathVariable用法

带占位符的 URL 是 Spring3.0 新增的功能,通过@PathVariable注解,我们可以获取网络url中的一部分作为controller方法中的参数。使用示例如下:

html:

<a href="/test/3">

java:

@RequestMapping("/test/{id}")
    public void test(@PathVariable("id") Integer id)
    {
        System.out.println("test:"+id);
    }

结果是输出:

test:3

猜你喜欢

转载自blog.csdn.net/qq_37856300/article/details/86591286