【问题标题】:How to support wrapping variable in braces with Spring GetMapping annotation如何使用 Spring GetMapping 注释支持在大括号中包装变量
【发布时间】:2024-03-09 14:45:01
【问题描述】:

我需要支持使用 Spring GetMapping 注释将 id 列表包装在花括号中。

当我像这样使用方括号时,它可以工作:

@GetMapping("/get/[{ids}]")

但是双括号,一切都爆炸了

@GetMapping("/get/{{ids}}")

例外:org.springframework.web.util.pattern.PatternParseException: Not allowed to nest variable captures

【问题讨论】:

    标签: spring get-mapping


    【解决方案1】:

    REST api: requesting multiple resources in a single get 可能重复

    但是,既然您知道如何使用[] 表示法请求多个资源;我在这里给出我的想法。

    我建议不要使用双括号作为获取多个资源的不推荐模式(请参阅:REST api: requesting multiple resources in a single get)。

    如果您仍然想要/必须使用双括号模式,您可以使用 URL 编码或编写自己的参数解析器等变通方法。

    【讨论】: