【发布时间】:2019-07-31 07:38:58
【问题描述】:
我们正在从 struts 1.3 框架迁移到 spring mvc。在struts 框架中,我们使用了ActionForm 类型的表单。我们在会话范围内维护它。当我们浏览屏幕(A->B->C)时,我们会重置表单的某些属性。如果我们从屏幕 A 导航到 B,我们传递参数 x=1,并且在表单的属性“x”中填充相同的值。但在从 B 导航到 C 之前,我们重置 x=null,因为屏幕 B 没有传递参数 x,我们不希望 x 保持从屏幕 A 收集的值。 在Struts中,每次填充参数之前都会自动调用表单中的reset方法。在Spring中,我们传递给控制器方法的模型需要在从请求参数填充之前重置。我们是否有在 Spring MVC 中实现类似的功能?
protected void processPopulate(HttpServletRequest request,
HttpServletResponse response, ActionForm form, ActionMapping mapping)
throws ServletException {
if (form == null) {
return;
}
// Populate the bean properties of this ActionForm instance
if (log.isDebugEnabled()) {
log.debug(" Populating bean properties from this request");
}
form.setServlet(this.servlet);
form.reset(mapping, request);
if (mapping.getMultipartClass() != null) {
request.setAttribute(Globals.MULTIPART_KEY,
mapping.getMultipartClass());
}
RequestUtils.populate(form, mapping.getPrefix(), mapping.getSuffix(),
request);
【问题讨论】:
标签: spring spring-mvc struts struts-1