【发布时间】:2018-06-07 07:01:00
【问题描述】:
我正在将 Struts 1 应用程序移植到 Struts 2。
在 Struts 1 应用程序中,有一个继承自 org.apache.struts.actions.DispatchAction 的 CommonAction 类。
public class CommonAction extends DispatchAction
CommonAction 类也是应用程序中所有其他 Action 类的超类,例如
public class ManageProfilesAction extends CommonAction
ManageProfilesAction 和CommonAction 等子类都有接收来自网络的请求的操作方法。对于ManageProfilesAction,关联的表单bean 是ManageProfilesForm,而CommonAction 的表单bean 名为CommonForm。
现在使用 Struts 2 方法,我声明 CommonAction 和 ManageProfilesAction 喜欢
public class CommonAction implements ServletRequestAware, ModelDriven<? extends CommonForm> {
protected CommonForm form = new CommonForm();
@Override
public CommonForm getModel() {
return form;
}
}
public class ManageProfilesAction extends CommonAction {
private ManageProfilesForm form = new ManageProfilesForm();
@Override
public ManageProfilesForm getModel() {
return form;
}
}
这样CommonAction 及其子类(如ManageProfilesAction)都可以具有接收Web 请求以及相关模型/表单的方法;分别为CommonForm 和ManageProfilesForm。
但是,我遇到了编译器错误:
public class CommonAction implements ServletRequestAware, ModelDriven<? extends CommonForm> {
required: class or interface without bounds
found: ? extends CommonForm
它是否可以使用一些 Java 泛型魔法或者我需要彻底改变设计?
【问题讨论】:
标签: java generics struts2 model-driven