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

相关文章:

  • 2022-12-23
  • 2022-01-19
  • 2022-01-17
  • 2022-02-28
  • 2022-12-23
  • 2021-10-10
  • 2021-07-10
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-17
  • 2020-05-07
  • 2022-12-23
  • 2021-09-14
  • 2022-12-23
相关资源
相似解决方案