As of Spring MVC 3, AbstractCommandController
is deprecated so you can no longer specify the command class in setCommandClass()
. Instead you hard-c
Instantiation of the command object is the only place where Spring needs to know a command class. However, you can override it with @ModelAttribute
-annotated method:
@RequestMapping(method = RequestMethod.POST)
public void show(HttpServletRequest request,
@ModelAttribute("objectToShow") Object objectToShow)
{
...
}
@ModelAttribute("objectToShow")
public Object createCommandObject() {
return getCommandClass().newInstance();
}
By the way, Spring also works fine with the real generics:
public abstract class GenericController<T> {
@RequestMapping("/edit")
public ModelAndView edit(@ModelAttribute("t") T t) { ... }
}
@Controller @RequestMapping("/foo")
public class FooController extends GenericController<Foo> { ... }