利用springboot如何实现一个过滤器功能-创新互联
创新互联www.cdcxhl.cn八线动态BGP香港云服务器提供商,新人活动买多久送多久,划算不套路!

利用springboot如何实现一个过滤器功能?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
拦截器定义:
@WebServlet
public class ActionInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
// System.out.println(">>>MyInterceptor1>>>>>>>在请求处理之前进行调用(Controller方法调用之前)");
// 获取系统时间
Calendar ca = Calendar.getInstance();
int hour = ca.get(Calendar.HOUR_OF_DAY);
// 设置限制运行时间 0-4点
if (hour < 4) {
return true;
}
return false;
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception {
// System.out.println(">>>MyInterceptor1>>>>>>>请求处理之后进行调用,但是在视图被渲染之前(Controller方法调用之后)");
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
throws Exception {
// System.out.println(">>>MyInterceptor1>>>>>>>在整个请求结束之后被调用,也就是在DispatcherServlet
// 渲染了对应的视图之后执行(主要是用于进行资源清理工作)");
}
} 本文标题:利用springboot如何实现一个过滤器功能-创新互联
网站URL:http://www.jxjierui.cn/article/shdjg.html


咨询
建站咨询
