【问题标题】:Insert referenced variable into RequestMapping在 RequestMapping 中插入引用变量
【发布时间】:2017-02-14 12:36:20
【问题描述】:

您好,我正在强制解决与 @RequestMapping 相关的问题。我正在尝试将变量从另一个类插入 URL 并在正则表达式中设置范围。你能告诉我这是否可能吗?

控制器:

@RequestMapping(value = "/v{:[1-currentVersion]}/dictionary")

具有 currentVersion 值的另一个类

public static int currentVersion = 1;

【问题讨论】:

    标签: java spring url request-mapping


    【解决方案1】:

    很遗憾,你不能这样做,因为注解不支持非常量属性值。只有当currentVersion 可以是final - 它才会起作用:

    public final static int currentVersion = 1;
    // ...
    @RequestMapping(value = "/v{:[1-"+currentVersion+"]}/dictionary")
    

    此外,从一般的角度来看,请求映射它自己是相当静态的事情。如果你有一些动态变化的值,你只能在你的方法体内检查它们。

    【讨论】:

      猜你喜欢
      • 2011-06-27
      • 2020-11-07
      • 1970-01-01
      • 1970-01-01
      • 2016-01-05
      • 1970-01-01
      • 2021-03-23
      • 2019-06-19
      • 1970-01-01
      相关资源
      最近更新 更多