0
由于代码共享而由SuperController类处理的Post方法。我猜如@Controller
和@SessionAttributes
是可继承的,所以我只需要把它们放在subController类中。我是否正确假设?我是否必须在SuperController类中放置@Controller或@SessionAttributes?
-------------------------------------------------------
@Controller
@SessionAttributes("form")
@RequestMapping(value = "/sample")
public class SampleController extends BaseController {
@RequestMapping(method = RequestMethod.GET)
public String getCreateForm(Model model) {
model.addAttribute("form", new SubAForm());
return "sample/input";
}
}
-------------------------------------------------------
public class BaseController {
@RequestMapping(method = RequestMethod.POST)
public String register(@ModelAttribute("form") SuperForm form, Model model) {
return "sample/input";
}
}
-------------------------------------------------------
public class SuperForm {
private Long superId;
public Long getSuperId() {
return superId;
}
public void setSuperId(Long superId) {
this.superId = superId;
}
}
-------------------------------------------------------
public class SubAForm extends SuperForm {
private Long subAId;
public Long getSubAId() {
return subAId;
}
public void setSubAId(Long subAId) {
this.subAId = subAId;
}
}
-------------------------------------------------------
<form:form modelAttribute="form" method="post">
<fieldset>
<legend>SUPER FIELD</legend>
<p>
SUPER ID:<form:input path="superId" />
</p>
</fieldset>
<fieldset>
<legend>SUB A FIELD</legend>
<p>
SUB A ID:<form:input path="subAId" />
</p>
</fieldset>
<p>
<input type="submit" value="register" />
</p>
</form:form>
@ @SessionAttributes中的@Inherited存在。它似乎声明为可继承的注释..对不起,我发布了一个愚蠢的问题。 – zono 2011-02-06 16:24:01