@InterceptorRefs

需要引入org.apache.struts2.convention.annotation.InterceptorRefs,配合@InterceptorRef使用,通过它定义一些拦截器。参考样例如下:

UserAction.java   [color=red]方式一,定义在方法上面[/color]
public class UserAction extends BaseAction {
......
@Action(value = "testInter",
results = @Result(name =INTERCEPTOR_ERROR, location = "inter-error..action?id=${id}"),
interceptorRefs = @InterceptorRef("parmsUrl")
)
public String testInter(){
......
}



UserAction.java                 [color=red]方式二,定义在类上面[/color]
@Results( { ......,
@Result(name = UserAction.INTERCEPTOR_ERROR, location = "inter-error.action?id=${id}", type = "redirect")
})
@InterceptorRefs( {@InterceptorRef("defaultStack"),@InterceptorRef(value="parmsUrl",params={"includeMethods","testInter"})})

public class UserAction extends BaseAction {
......
public String testInter(){
......
}



ParamUrlInterceptor.java
public class ParamUrlInterceptor implements Interceptor {
@Override
public String intercept(ActionInvocation invocation) throws Exception {
业务逻辑,实现拦截......
}
......



struts.xml

......



你可能感兴趣的:(Struts,Annotation,struts,annotation,interceptorrefs)