With Spring MVC, it’s easy to express a concept like “A user is submitting the form if they use POST or if they include the ‘isSubmit’ parameter.” You’d just extend SimpleFormController and override the isFormSubmission method.
However, Spring MVC now uses these neat annotations like @RequestMapping to handle requests. @RequestMapping has an obvious filter for whether somebody used a GET or a POST, but I don’t see any inherent support for all of the useful logic SimpleFormController provided. Is it still available to me with annotations?
So, after a bit of investigation, there are in fact a couple of ways to handle this situation.
The first way is to go ahead and use a
SimpleFormControllerwith with@RequestMappingannotation at the class level. A lesser-known but pretty cool property of @RequestMapping is that it knows perfectly well how to deal with the classes that implement Spring’sControllerinterface. The only downside here is that I’m still using the old MVC interfaces and classes, and they’re going to be deprecated in Spring 3.0.The second way was pointed out by kgiannakakis above. Simply create a
@RequestMappingmethod for every way that the submit can be called, and have them all just call a single submit method, either in a constructor-chaining style or with some private method. Simple and easy to understand. Thanks, kgiannakakis!