Example:
class CommonController {
@ModelAttribute("refs")
public List getRef() {
...
}
@ModelAttribute("refs2")
public List getRef2() {
...
}
}
class MyControll开发者_如何学Pythoner extends CommonController {
@RequestMapping("/my")
public String request() {
return "/my";
}
}
The ModelAttribute objects will be available on my page?
Why you wouldn't recommend to do it?
For example - I have two controllers create and edit.
They use the same references getting through @ModelAttribute and instean to copy past it would be better to create parent class for controllers.
class ReferenceParentController {
@ModelAttribute("refs")
public List getRef() {
...
}
@ModelAttribute("refs2")
public List getRef2() {
...
}
}
class Create extends ReferenceParentController {
...
}
class Edit extends ReferenceParentController {
...
}
According to this answer in Spring forum you can:
http://forum.springsource.org/showthread.php?103368-spring-3-mvc-help-with-multiple-forms-on-one-page&p=345386#post345386
But personally I wouldn't recommend to do it.
精彩评论