1. Custom interceptor implements HandlerInterceptor interface
/** * * Created by zhh on 2018/04/20. */public class MyInterceptor implements HandlerInterceptor { @Autowired private NetworkProxyInfoService networkProxyInfoService; @Override public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3) throws Exception { // TODO Auto-generated method stub } @Override public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3) throws Exception { networkProxyInfoService.getAllNetworkProxyInfoByIsValid(GobalConstant.ProxyValid.VALID); } @Override public boolean preHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2) throws Exception { // TODO Auto-generated method stub return true; }} 2. Custom interceptor configuration
/** * * Created by zhh on 2018/04/20. */@Configurationpublic class MyWebMvcConfig extends WebMvcConfigurerAdapter { /** * Write custom interceptors as beans to configuration* @return */ @Bean public MyInterceptor myInterceptor() { return new MyInterceptor(); } @Override public void addInterceptors(InterceptorRegistry registry) { /** * Multiple interceptors form an interceptor chain* addPathPatterns Used to add interception rules* excludePathPatterns User exclusion interception*/ registry.addInterceptor(myInterceptor()).addPathPatterns("/**"); super.addInterceptors(registry); } }The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.