码迷,mamicode.com
首页 > 其他好文 > 详细

AOP 实现请求参数打印

时间:2017-05-12 17:27:03      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:etl   res   bsp   actor   cto   asm   poi   style   import   

1.编写打印发放

import java.util.Enumeration;

import javax.servlet.http.HttpServletRequest;

import org.aspectj.lang.JoinPoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

public class LogAspect {

    private static Logger LOGGER = LoggerFactory.getLogger(LogAspect.class);

    public void doBefore(JoinPoint joinPoint) {

        // 接收到请求,记录请求内容
        LOGGER.info("WebLogAspect.doBefore()");
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder
                .getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();

        Enumeration<String> enu = request.getParameterNames();
        LOGGER.debug("CLASS_METHOD : {}.{}", joinPoint.getSignature().getDeclaringTypeName() , joinPoint.getSignature().getName());
        while (enu.hasMoreElements()) {
            String paraName = (String) enu.nextElement();
            LOGGER.debug("{}:{}",paraName,request.getParameter(paraName));
        }
    }

}

2.配置 AOP

    <aop:config>  
        <aop:aspect id="logAspect" ref="logAspectBean">  
            <aop:pointcut id="allMethod"   
                expression="execution(* com.qi.jr.fp.test..*.*(..))"/>   
            <aop:before method="doBefore" pointcut-ref="allMethod" />  
        </aop:aspect>  
    </aop:config>  
    
    <bean id="logAspectBean" class="com.qi.aop.LogAspect"></bean>

 

ok 这样进入方法之前参数就会被打印出来了

AOP 实现请求参数打印

标签:etl   res   bsp   actor   cto   asm   poi   style   import   

原文地址:http://www.cnblogs.com/yun965861480/p/6846229.html

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