基於註解實現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("呵呵");
    }

}

 

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