Is there a way to use an Enum value in a RequestMapping?
@RequestMapping(value = "/example",
method = RequestMethod.POST)
public final void foo(final HttpServletResponse response,
I want to use a URL value that is already stored in an Enum.
However, I get compile time errors when I try to put anything except a String literal in the RequestMapping
.
How does it know the difference between a String literal and a String that is not a String literal ( not sure what that's called ) ?
This is what I tried but it failed at compile time:
@RequestMapping(value = FooEnum.Example.getStringValue(),
method = RequestMethod.POST)
public final void foo(final HttpServletResponse response,
I also tried using String.format
but it doesn't like that either:
@RequestMapping(value = String.format("%s", FooEnum.Example.getStringValue()),
method = RequestMethod.POST)
public final void foo(final HttpServletResponse response,
Only literal values can be assigned to annotation attributes because they must be known at compile-time when annotations are processed. Yes, you could use an enum value, where "enum value" is FooEnum.Example
, but not on an attribute that takes a String value, and you can't call a method on it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With