问题描述
我正在尝试在 Struts2 中找到 org.apache.struts.actions.dispatchAction.types
的替代品。
以下代码片段:
if(types != null)
{
if(types.length == forward.length)
{
select.add(type[0]);
}
}
forward
是字符串类型对象,select
是列表类型数组。
解决方法
DispatchAction.types
的文档:
types
protected java.lang.Class[] types
反射方法调用的参数类型类集。这些对于所有调用都是相同的,因此只需计算一次。
Struts2 中没有相同的东西。您应该刷新您的想法,以了解 struts2 的工作方式与 struts-1 不同。
例如,您可以将您的操作直接映射到方法。您可以使用 SMI 进行方法调用,如 this answer
您应该将注释直接放在方法上。因为如果你把它放在类上,默认方法 execute()
用于映射。
@ParentPackage("basePackage")
@Namespace("/")
@AllowedMethods("test")
public class UserAction {
@Action(value = "userAction")
public String test() {
// your code
rerurn Action.SUCCESS;
}
}
或使用通配符映射,如 this 答案。
如果在同一个包中使用,操作名称将被覆盖。操作名称映射到特定方法或 execute
。
您可以使用通配符映射在操作中放置方法名称。
<action name="*product" class="com.DispatchAction" method="{1}">