首页 > 代码库 > SpringAOP在登陆控制上的使用

SpringAOP在登陆控制上的使用

 

 

首先创建一个切面,设置切点和环绕通知

@Aspect@Componentpublic 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");    }}

 

SpringAOP在登陆控制上的使用