Is it possible to use a value for @RequestMapping, which is a string but not a string literal?

Is there a way to use the Enum value in 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 Enum.

However, I get compile-time errors when I try to put anything other than a string literal in RequestMapping.

How does he know the difference between a string literal and a string that is not a string literal (not sure what is 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 I also don't like this:

@RequestMapping(value = String.format("%s", FooEnum.Example.getStringValue()), 
method = RequestMethod.POST)
public final void foo(final HttpServletResponse response,
+5
source share
2 answers

, . , , " " FooEnum.Example, , String, .

+1

URL ; , URL- , . , ? , Spring Handler bean URL-?

Spring , , @Value , @RequestMapping

URL- , @PathVariable

0

All Articles