Reputation: 1465
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() {
}
Upvotes: 55
Views: 59844
Reputation:
or you could do something like:
@RequestMapping("/test.html")
public void writeSomeDay(@RequestParam String day) {
// code to handle "day" comes here...
}
Upvotes: 53
Reputation: 6095
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() {
}
Upvotes: 80