AOP中獲取自定義註解的屬性值

自定義註解

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface SystemLog {

	public String description() default "";
}

用在方法上

@ResponseBody
@ValidRequestBody
@RequestMapping("/login")
@SystemLog(description="登錄")
public GlobalResponse login(@RequestBody @Valid User user, BindingResult bindingResult){
    ......
}

獲取註解的屬性值

@Around("@annotation(com.xxx.xxx.xxx.SystemLog)")
public Object around(ProceedingJoinPoint joinPoint) throws Throwable{
    SystemLog systemLog = ((MethodSignature)joinPoint.getSignature()).getMethod().getAnnotation(SystemLog.class);    
    ......
}

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