Can I do something like this with Spring MVC ?
@RequestMapping(value = "/{root}")
public abstract class MyBaseController {
@PathVariable(value = "root")
protected ThreadLocal<String> root;
}
@Controller
public class MyController extends MyBaseController {
@RequestMapping(value = "/sayHello")
@ResponseBody
public String hello() {
return "Hello to " + this.root.get();
}
}
When I request to http://..../roberto/sayHello
, I get this as response:
Hello to roberto
According to the docs:
http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/bind/annotation/PathVariable.html
the PathVariable annotation is itself annotated with @Target(value=PARAMETER)
so it shouldn't be possible to be used the way you're saying as it's only applicable to method parameters.
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