程序员一代码搬运工
【Java学习心得和Java学习技术个人总结】

Spring mvc aop to get request and response

@Aspect
public class LoggingAspect {

    
    @Before("execution(* xxxxxxxxxxx(..))")
    public void logBefore(JoinPoint joinPoint) {
    / /此处可以通过以下方法得到REQUEST,另外也可以通过参数方法得
       HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
 
        System.out.println("******"+request.getParameter("username"));
        System.out.println("******");
        System.out.println("******");
        System.out.println("******");
        System.out.println("logBefore() is running!");
        System.out.println("hijacked : " + joinPoint.getSignature().getName());
        System.out.println("******");
        //Currently, I just use this method to get repines, another way is to use filter to set request and response, then use them in AOP method

        HttpServletResponse response = (HttpServletResponse) joinPoint.getArgs()[0];
        
        

    }
 
}

 

赞(0)
未经允许不得转载:程序员一代码搬运工 » Spring mvc aop to get request and response
分享到: 更多 (0)