描述:
已创建一个单独的模块实现AOP的操作,其他主要代码如下:
1.1 自定义注解:
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
@Documented
public @interface LogAnnotation {
/**
* 模块名
*/
String moduleName() default "";
/**
* 操作描述
*/
String desc()default "";
}
1.2 AOP切面
@Component
@Aspect
public class LogInterceptor {
@Autowired
private SysLogService sysLogService;
@Autowired
private HttpServletRequest request;
@Pointcut("@annotation(com.weblog.syslog.annotation.LogAnnotation)")
public void pointCut(){}
@After("pointCut()")
public void afterReturning(JoinPoint joinpoint){
try {
SysLog sysLog=new SysLog();
String userid= (String) request.getAttribute("id");
...以下是获取方法参数等相关信息的操作
注解路径:
在其他服务中引入该项目依赖后使用:
@PutMapping(value="/{id}")
@LogAnnotation(moduleName = "文章/标签",desc = "标签修改")
public Result update(@RequestBody Tag tag, @PathVariable String id ){
````
没有任何报错,但是没有进入到切面,这方面掌握的不是特点透彻,不知道哪里有问题,请问有了解的大佬嘛,非常感谢指点!