一、配置xml
<interceptors>
<interceptor name="myInterceptor" class="com.bp.zhzs.bpjagl.action.MyInterceptor"></interceptor>
<interceptor-stack name="myStack">
<interceptor-ref name="myInterceptor"/>
<interceptor-ref name="defaultStack"/>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="myStack"></default-interceptor-ref>
MyInterceptor .java
package com.bp.zhzs.bpjagl.action;
import com.alibaba.fastjson.JSON;
import com.bp.zhzs.fdchygl.model.LayuiTableEntity;
import com.bp.zhzs.srfx.model.SqlUtil;
import com.bp.zhzs.util.dymanic.SpringUtils;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
import org.apache.struts2.dispatcher.HttpParameters;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Component
@Aspect
@Order(3)
public class MyInterceptor implements Interceptor {
private Logger log = LoggerFactory.getLogger(this.getClass());
@Autowired
private SqlUtil sqlUtil;
@Override
public void destroy() {
}
@Override
public void init() {
if (sqlUtil == null) {
SqlUtil sqlUtil = (SqlUtil) SpringUtils.applicationContext.getBean("sqlUtil");
this.sqlUtil = sqlUtil;
}
}
@Override
public String intercept(ActionInvocation invocation) throws Exception {
log.debug("进入拦截器");
//类名
String simpleName = invocation.getAction().getClass().getSimpleName();
//方法名
String name = invocation.getProxy().getMethod();
//参数
HttpParameters parameters = invocation.getInvocationContext().getParameters();
//业务逻辑处理
//调用Action执行
String result = invocation.invoke();
return result;
}
}