Spring AOP中获取request,response

注意将其写在方法里

HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();

HttpServletResponse response=((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse()
@Around(value = "@annotation(logAop)")
public Object interceptorLog(ProceedingJoinPoint pj, LogAop logAop) {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        HttpServletResponse response=((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse()
        SysUser user = (SysUser) request.getAttribute("sysUser");
        System.out.println("用户名:" + user.getUsernamezh());
        System.out.println("模块名称:" + logAop.modulName());
        System.out.println("操作内容:" + logAop.action());
}

你可能感兴趣的:(Spring AOP中获取request,response)