有沒有辦法在RequestMapping中使用枚舉值?是否有可能爲@RequestMapping使用一個字符串而不是字符串的值?
@RequestMapping(value = "/example",
method = RequestMethod.POST)
public final void foo(final HttpServletResponse response,
我想使用已經存儲在枚舉一個URL值。
但是,當我嘗試在RequestMapping
中放入除String字符串之外的任何內容時,會出現編譯時錯誤。
它如何知道一個字符串字符串和一個不是字符串字符串的字符串之間的區別(不知道是什麼)?
這是我嘗試,但它沒有在編譯時:
@RequestMapping(value = FooEnum.Example.getStringValue(),
method = RequestMethod.POST)
public final void foo(final HttpServletResponse response,
我使用String.format
也嘗試過,但它不喜歡,要麼:
@RequestMapping(value = String.format("%s", FooEnum.Example.getStringValue()),
method = RequestMethod.POST)
public final void foo(final HttpServletResponse response,
不是字面值* only *,而是常數(在編譯時)的值,甚至像「」PO「+」ST「這樣的表達式,只要它們的值爲一個常量。這就是爲什麼'RequestMethod.POST'是註解中有效的屬性值,但方法調用不是。 –