基于注解实现spring aop使用注解进行验证

@Aspect
@Component
public class DoneTimeAspect {

    @Around("@annotation(doneTime)")
    public Object around(ProceedingJoinPoint joinPoint, DoneTime doneTime) throws Throwable {
        System.out.println("吃提交");
        System.out.println("方法开始时间是:"+new Date());

        System.out.println("方法结束时间是:"+new Date()) ;
        // 拦截的方法名称。当前正在执行的方法
        String methodName = joinPoint.getSignature().getName();
        // 拦截的方法参数
        Object[] args = joinPoint.getArgs();
//        for ()
//        Object proceed = joinPoint.proceed();
        return null;
    }
}

@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface DoneTime {
    String param() default "";
}
@RestController
@RequestMapping("u")
@Api("Hellow 简单测试")
public class HelloController {

    @Autowired
    UserService usersService;

    @GetMapping("/hello")
    @DoneTime
    public void hello(){
        System.out.println("呵呵");
    }

}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章