diff --git a/Main.java b/Main.java index 1a68b2dd0a36d3447eed91dc217b0ec3bb12c172..c7cc4e20d8c902e7738ab1fbd4a43bd2ba721711 100644 --- a/Main.java +++ b/Main.java @@ -1,5 +1,13 @@ -class Main { - public static void main(String[] args) { - System.out.println("Hello world!"); - } +public class LoginInterceptor implements HandlerInterceptor { + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { + // 判断用户是否登录,这里使用 sa-token 提供的方法进行判断 + if (StpUtil.isLogin()) { + return true; // 已登录,放行 + } else { + // 未登录,重定向到登录页 + response.sendRedirect("/login"); + return false; + } + } } \ No newline at end of file