码迷,mamicode.com
首页 > 编程语言 > 详细

SpringAOP在登陆控制上的使用

时间:2016-09-21 14:27:30      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:

 

 

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

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

 

SpringAOP在登陆控制上的使用

标签:

原文地址:http://www.cnblogs.com/ljdblog/p/5892438.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!