0

我正在从 Struts2 控制器转向 Spring MVC 2.5

在 Struts2 的情况下,OGNL 曾经负责填充 Action 类的属性。在 Spring MVC 2.5 中,它们也有一个SimpleFormController可以setCommandClass(UserDefinedBean.class)在构造函数中调用来从参数自动填充 bean 类的属性。

但是如果MultiActionController(这对我的要求似乎非常有用)我正在request.getParameter("paramName");从请求中获取参数。有什么方法可以利用setCommandClass()withMultiActionController吗?

4

1 回答 1

3

您可以将命令对象作为操作方法中的参数之一,例如:

public (ModelAndView | Map | String | void) actionName(HttpServletRequest request, HttpServletResponse response, Object commandObject);

对于数据绑定的广泛使用,您始终可以覆盖 initBinder(...)方法以拥有您的自定义绑定和验证器。

为什么使用 Spring 2.5.x 之间?为什么不是 Spring 3.0.x ?通过使用注释,您可以在新版本中获得更大的灵活性。甚至 Spring 也不推荐使用旧的扩展控制器的方法。只是一个建议,因为我不确定您的设计或要求。

于 2012-04-24T09:26:50.760 回答