首先jresplus框架提供了一个接口拦截器
package com.hundsun.jresplus.web.adapter;
import java.lang.reflect.Method;
import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.servlet.ModelAndView;
public interface AnnotationMethodHandlerInterceptor
{
public abstract void preInvoke(Method method, Object obj, ServletWebRequest servletwebrequest);
public abstract void postInvoke(Method method, Object obj, ServletWebRequest servletwebrequest, ModelAndView modelandview);
}
然后写了一个控制器拦截器ActionInterceptor,实现了上述拦截器接口,只要进入控制器,就会调用这个拦截器
package com.hundsun.ue.web.interceptor;
/**
* 功能说明: 控制器拦截器<br>
*/
@Component
public class ActionInterceptor extends AnnotationMethodHandlerInterceptorAdapter implements InitializingBean, LogUtils {
@Autowired
private ObjectFactory objectFactory;
private List<IInterceptorHandler> interceptorHandlers = Collections.emptyList();
@Override
public void afterPropertiesSet() throws Exception {
this.interceptorHandlers = objectFactory.getBeansOfType4List(IInterceptorHandler.class);
}
@Override
public void preInvoke(Method handlerMethod, Object handler, ServletWebRequest webRequest) {
if (CollectionUtils.isNotEmpty(this.interceptorHandlers)) {
for (IInterceptorHandler interceptorHandler : this.interceptorHandlers) {
interceptorHandler.preHandle(handlerMethod, webRequest);
}
}
}
@Override
public void postInvoke(Method handlerMethod, Object handler, ServletWebRequest webRequest, ModelAndView mav) {
try {
if (CollectionUtils.isNotEmpt