1.新建一个拦截器控制器
@Controller
public class MyInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
System.out.println("=======拦截器=====");
return true;
}
}
2.配置拦截器
@SpringBootApplication
@MapperScan("com.haoxiaohuo.archer.mapper")
public class ArcherApplication extends WebMvcConfigurerAdapter {
public static void main(String[] args) {
SpringApplication.run(ArcherApplication.class, args);
}
@Bean
public MyInterceptor myInterceptor(){
return new MyInterceptor();
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(myInterceptor()).addPathPatterns("/*");
}
}