@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("呵呵");
}
}