拦截器篇
1,实现拦截器。
implement HandlerInterceptor(还有一种继承)
有三个方法:
preHandle:前置方法,为true继续,false停止
postHandle:业务层完成后,返回数据结果,但是在生成视图前
afterCompletion:暂时没用到 (网上解释:在DispatcherServlet完全处理完请求后被调用,可用于清理资源等。返回处理(已经渲染了页面))
2,添加拦截器(注册拦截器)
implements WebMvcConfigurer
registry.addInterceptor(new Interceptor());注册拦截器,添加到容器中
interceptorRegistration.addPathPatterns("/**");拦截的url设置
手动异常类篇
1,写一个类继承Exception或子类
2,要抛的地方throw 自定义对象
例: HandlerException extends Exception
throw new HandlerException(“手动异常类”)