Spring - Annotation-based controller - RequestMapping based on query string

In Annotation-based Spring controller, is it possible to map different query strings using @RequestMapping for different methods?

for example

 @RequestMapping("/test.html?day=monday") public void writeMonday() { } @RequestMapping("/test.html?day=tuesday") public void writeTuesday() { } 
+52
spring annotations
Jan 18 '09 at 5:15
source share
2 answers

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 display based on the presence or absence of a parameter:

 @RequestMapping("/test.html", params = "day") public void writeSomeDay() { } @RequestMapping("/test.html", params = "!day") public void writeNoDay() { } 
+77
Jan 18 '09 at 5:22
source share

or you can do something like:

 @RequestMapping("/test.html") public void writeSomeDay(@RequestParam String day) { // code to handle "day" comes here... } 
+49
Jul 06 '09 at 13:33
source share



All Articles