In Spring annotation-based controller, is it possible to map different query strings using @RequestMapping
to different methods?
For example
@RequestMapping("/test.html?day=monday")
public void writeMonday() {
}
@RequestMapping("/test.html?day=tuesday")
public void writeTuesday() {
}
RequestMapping annotation is used to map web requests onto specific handler classes and/or handler methods. @RequestMapping can be applied to the controller class as well as methods.
The @RequestParam annotation is used with @RequestMapping to bind a web request parameter to the parameter of the handler method.
A Callable can be returned when the application wants to produce the return value asynchronously in a thread managed by Spring MVC. A DeferredResult can be returned when the application wants to produce the return value from a thread of its own choosing.
The @RequestMapping annotation can be applied to class-level and/or method-level in a controller. The class-level annotation maps a specific request path or pattern onto a controller. You can then apply additional method-level annotations to make mappings more specific to handler methods.
Yes, you can use the params element:
@RequestMapping("/test.html", params = "day=monday")
public void writeMonday() {
}
@RequestMapping("/test.html", params = "day=tuesday")
public void writeTuesday() {
}
You can even map based on the presence or absence of a param:
@RequestMapping("/test.html", params = "day")
public void writeSomeDay() {
}
@RequestMapping("/test.html", params = "!day")
public void writeNoDay() {
}
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