From 83fcf0ec10627f73f89c053632b4b09e9141d6a7 Mon Sep 17 00:00:00 2001 From: pxh4iabou <2044878308@qq.com> Date: Sun, 30 Apr 2023 01:18:05 +0800 Subject: [PATCH] ADD file via upload --- .../java/com/common/config/MyInterceptor.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/main/java/com/common/config/MyInterceptor.java diff --git a/src/main/java/com/common/config/MyInterceptor.java b/src/main/java/com/common/config/MyInterceptor.java new file mode 100644 index 0000000..b73a5d3 --- /dev/null +++ b/src/main/java/com/common/config/MyInterceptor.java @@ -0,0 +1,35 @@ +package com.example.common.config; + +import com.example.entity.Account; +import org.springframework.web.servlet.HandlerInterceptor; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * 拦截器 + * @author nsw + */ +public class MyInterceptor implements HandlerInterceptor { + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse + response, Object handler) throws Exception { + Account user = (Account) request.getSession().getAttribute("user"); + if (user == null) { + // 重定向到登录页 + response.sendRedirect("/end/page/login.html"); + return false; + } + 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 { + } +}