标签:
首先创建一个切面,设置切点和环绕通知
@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"); } }
标签:
原文地址:http://www.cnblogs.com/ljdblog/p/5892438.html