zoukankan      html  css  js  c++  java
  • 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());
    }
    }
  • 相关阅读:
    UVA1585
    暑期第二场-1
    UVA11582
    UVA10006
    HDU1005
    HDU2035
    POJ:2492-Bug's Life(二分图的判定)
    Codeforces:68A-Irrational problem(暴力大法好)
    Codeforces Round #456 (Div. 2) B. New Year's Eve
    Codeforces Round #456 (Div. 2) A. Tricky Alchemy
  • 原文地址:https://www.cnblogs.com/zhcnblog/p/8944989.html
Copyright © 2011-2022 走看看