SpringMvc自定义拦截器(注解)代码实例
程序员文章站
2022-07-08 09:14:19
拦截器自定义拦截器实现handlerinterceptor接口的三个方法。public class myinterceptor implements handlerinterceptor{ @ove...
拦截器
自定义拦截器实现handlerinterceptor接口的三个方法。
public class myinterceptor implements handlerinterceptor{ @override public boolean prehandle(httpservletrequest request, httpservletresponse response, object handler) throws exception { //拦截内容 //放行 return true; } @override public void posthandle(httpservletrequest request, httpservletresponse response, object handler, modelandview modelandview) throws exception { //请求来时执行 } @override public void aftercompletion(httpservletrequest request, httpservletresponse response, object handler, exception ex) throws exception { //响应来时执行 } }
springmvc配置文件
//将拦截器放入mvc容器中 @bean public myinterceptor myinterceptor(){ return new myinterceptor(); } //添加拦截器,并配置拦截路径 @override public void addinterceptors(interceptorregistry registry) { //配置拦截器 registry.addinterceptor(myinterceptor()).addpathpatterns("/**"); }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。