SpringBoot@PathVariable注解

Posted Alkaid:

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SpringBoot@PathVariable注解相关的知识,希望对你有一定的参考价值。

@PathVariable是spring3.0的一个新功能:接收请求路径中占位符的值

语法

@PathVariable("xxx")

通过 @PathVariable 可以将URL中占位符参数xxx绑定到处理器类的方法形参中@PathVariable("xxx")

举例

    @GetMapping("/goods/id")
    public Goods goods(@PathVariable(name = "id") Integer id) 
        Goods g = new Goods(id, "草莓", 6.5, new Date(), "好吃");
        return g;
    

请求路径:http://localhost:8080/goods/1

以上是关于SpringBoot@PathVariable注解的主要内容,如果未能解决你的问题,请参考以下文章

Springboot@PathVariable注解使用--请求路径占位符

SpringBoot-@PathVariable

SpringBoot-@PathVariable

Java 注解自定义注解 ( 注解解析 )

Java 注解自定义注解 ( 使用注解实现简单测试框架 )

Java自定义注解的使用