日志无法记录
package ms.global; import ms.entity.Log; import ms.entity.Staff; import ms.service.LogService; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; /** * Created by Raymond on 2018/11/25. */ @Component @Aspect public class LogAdvice { @Autowired private LogService logService; @After("execution(* ms.controller.*.*(..)) &&!execution(* ms.controller.SelfController.*(..)) &&!execution(* ms.controller.*.to*(..))") public void operationLog(JoinPoint joinPoint){ Log log = new Log(); log.setModule(joinPoint.getTarget().getClass().getSimpleName()); log.setOperation(joinPoint.getSignature().getName()); HttpServletRequest request =(HttpServletRequest) joinPoint.getArgs()[0]; HttpSession session = request.getSession(); Object object = session.getAttribute("USER"); Staff staff = (Staff)object; System.out.println(staff); log.setOperator(staff.getAccount()); log.setResult("成功"); logService.addOperationLog(log); } @AfterThrowing(throwing = "e",pointcut = "execution(* ms.controller.*.*(..)) && !execution(* ms.controller.SelfController.*(..))") public void systemLog(JoinPoint joinPoint,Throwable e){ Log log = new Log(); log.setModule(joinPoint.getTarget().getClass().getSimpleName()); log.setOperation(joinPoint.getSignature().getName()); HttpServletRequest request =(HttpServletRequest) joinPoint.getArgs()[0]; HttpSession session = request.getSession(); Object object = session.getAttribute("USER"); Staff staff = (Staff)object; log.setOperator(staff.getAccount()); log.setResult(e.getClass().getSimpleName()); logService.addSystemLog(log); } @After("execution(* ms.controller.SelfController.login(..))") public void loginLog(JoinPoint joinPoint) { log(joinPoint); } @Before("execution(* ms.controller.SelfController.logout(..))") public void loginOutLog(JoinPoint joinPoint){ log(joinPoint); } private void log(JoinPoint joinPoint){ Log log = new Log(); log.setModule(joinPoint.getTarget().getClass().getSimpleName()); log.setOperation(joinPoint.getSignature().getName()); HttpServletRequest request = (HttpServletRequest) joinPoint.getArgs()[0]; HttpSession session = request.getSession(); Object object = session.getAttribute("USER"); if (object == null) { log.setOperator(request.getParameter("account")); System.out.println("failure"); log.setResult("失败"); } else { Staff staff = (Staff) object; System.out.println(staff); log.setOperator(staff.getAccount()); log.setResult("成功"); } logService.addLoginLog(log); } }
1
收起
正在回答 回答被采纳积分+1
相似问题
登录后可查看更多问答,登录/注册
SSM主流框架入门与综合项目实战2018版
- 参与学习 人
- 提交作业 205 份
- 解答问题 4317 个
Java中非常实用的SSM整合开发内容,从Spring开始,到MyBaits的进阶内容,再到SpringMVC的应用,最后是SSM整合开发案例,逐步深入,助你成长为一名Java工程师!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星