首先创建一个切面,设置切点和环绕通知
@Aspect @Component public class UserLoginAOP { @Pointcut("execution(* com.shop.controller.user.*.*(..))") public void aspect() { } @Around("aspect()") public Object beforeExec(ProceedingJoinPoint joinPoint) throws Throwable { HttpSession session = (HttpSession) joinPoint.getArgs()[2]; HttpServletResponse response = (HttpServletResponse) joinPoint .getArgs()[1]; User user = (User) session.getAttribute("user"); if (user == null) { response.sendRedirect("/shop/jsp/toUserLogin.do"); return null; } else { return joinPoint.proceed(); } // System.out.println("check user login status"); } }
时间: 2024-10-25 14:30:26