2017-02-14 145 views
1

嗨我強迫問題連接到@RequestMapping。我想從另一個類的URL中插入變量,並在正則表達式中設置範圍。你能告訴我,如果有可能嗎?將引用變量插入到RequestMapping

控制器:

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

另一類隨着CURRENTVERSION值

public static int currentVersion = 1; 

回答

1

不幸的是,不,你不能做這樣的方式,因爲註釋不支持非恆定屬性值。只有currentVersion可以final - 它會工作:

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

而且,從一般來看,請求映射它的自我是相當靜態的東西。如果你有一些動態改變的值,你只能在方法體內檢查它們。

+1

是的,它非常有用,非常感謝。 –