参数上使用自定义注解在aop中无法获取到该参数
问题描述:
目标方法:
@ApiOperation(value="testRedis")
@RequestMapping(value = "/testRedis", method = RequestMethod.GET)
@DropDownSearch(key = "'bdt0010_'+#projectId")
public Object redisTest(String projectId, @SearchKeyWord String value){
System.out.printf("");
return BaseResult.successResultCreate("test",bdt0010Service.redisTest(projectId));
}
其中@DropDownSearch为自定义方法注解
@SearchKeyWord为自定义参数注解
在Aspect使用环绕通知:
public Object doAfterClearRedisCache(ProceedingJoinPoint joinPoint) throws Throwable {
//Class<?> targetClass = joinPoint.getTarget().getClass();
//获得参数列表
Object[] args = joinPoint.getArgs();
}
getArgs方法无法获取被@SearchKeyWord标记的参数对象。
此前未使用@SearchKeyWord注解时一切均正常。
请问是什么问题?
答
实际问题在于swaggerui标注的方法中,当方法参数被自定义注解标记后,该参数被认为是body类型,在使用swagger测试时无法正确将参数值传递到后台。
只需为参数再加上
@RequestParam(required = false)
即可
答
这样写,把你的注解作为方法的入参
/**
* 环绕增强,验证权限
* @param joinPoint 目标对象
* @param authCheck 自定义的注解,Around必须这样写,否则自定义的注解无法传入
* */
@Around("pointAll() && @annotation(authCheck)")
public Object before(ProceedingJoinPoint joinPoint, AuthCheck authCheck) throws Throwable