zoukankan      html  css  js  c++  java
  • AOP 实现请求参数打印

    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 这样进入方法之前参数就会被打印出来了

  • 相关阅读:
    组合数取模 Lucas定理
    关于上下界的二分查找
    POJ 1091 跳蚤
    Eular 函数模板
    POJ 数学(3)
    SRM 567 div2
    SRM 570 div2
    最大最小搜索,alpha beta 剪枝
    JavaScript:prototype属性使用方法
    ArcGIS网络分析之Silverlight客户端服务区分析(五)
  • 原文地址:https://www.cnblogs.com/yun965861480/p/6846229.html
Copyright © 2011-2022 走看看