一个Hello引发的Spring AOP 实战用法解析

实战用法:

  • 1:接口方法
package com.xxx.xxx.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/api/open")
public class OpenController {
   
    @RequestMapping(value = "/hello", method = { RequestMethod.GET })
    public JsonResult hello() {
        return new JsonResult("welcome to HOME");
    }

}

  • 2:定义切面
package com.xxx.xxx.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.an
上一篇:Pointcut注解表达式@target、@annotation、@within、this、target、within等


下一篇:自定义注解+AOP,优雅的打印方法接受和返回的参数内容