• Spring Boot 进阶之Web进阶 学习


    AOP 面向切面编程

    1.添加aop依赖

    pom.xml中添加

    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-aop</artifactId>
    </dependency>

    2.创建切面文件 HttpAspect.java
    @Aspect    //切面 注解
    @Component
    public class HttpAspect {

    private final static Logger logger = LoggerFactory.getLogger(HttpAspect.class); //日志记录

    @Pointcut("execution(public * com.example.girl.controller.GirlController.*(..))")
    private void log(){
    }


    @Before("log()")
    public void doBefor(JoinPoint joinPoint){

    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
    HttpServletRequest request = attributes.getRequest();

    logger.info("url={}",request.getRequestURL());
    logger.info("method={}",request.getMethod());
    logger.info("ip={}",request.getRemoteAddr());
    logger.info("class_method={}",joinPoint.getSignature().getDeclaringTypeName()+"."+joinPoint.getSignature().getName());
    logger.info("args={}",joinPoint.getArgs());
    }

    @After("log()")
    public void doAfter(){
    logger.info("doAfter.......");
    }

    @AfterReturning(returning = "object",pointcut = "log()")
    public void doAfterReturning(Object object){
    logger.info("response={}",object.toString());
    }
    }
  • 相关阅读:
    cocos2d-x CSV文件读取 (Excel生成csv文件)
    cocos2d-x 中 xml 文件读取
    String 类的实现
    json 文件解析与应用
    设计模式 之 《简单工厂模式》
    C++ 0X 新特性实例(比较常用的) (转)
    CCSpriteBatchNode CCSpriteFrameCache
    LongAdder
    ConcurrentHashMap源码
    HashMap源码
  • 原文地址:https://www.cnblogs.com/zhcnblog/p/8944989.html
Copyright © 2020-2023  润新知