问题
I have a requirement now, that is when using mybatis(especially those batch execute sql), check parameter first , if the parameter is null or empty , then just return, don't proceed and if the return type is List,eg.
List<User> getByIds(List<Long> idList)
return empty ArrayList, if the return type is void:
void batchInsert(List<User>)
return null. The purpose is to avoid this situation, eg.
select * from user where id in ()
insert into user(name,email) values ()
but from joinPoint I can't get return type,only can get args.
Object[] args = joinPoint.getArgs();
if(args!=null&&args.length=1){
if(args[0] instanceof List){
if(((List) obj).isEmpty()){
if(returnType.equals("java.util.List"))
return new ArrayList();
else if(returnType.equals("void"))
return null;
}
}
return joinPoint.proceed();
So how can I get return type in aop:around?
回答1:
To get method return type/class from a ProceedingJoinPoint
you can do this:
Signature signature = proceedingJoinPoint.getSignature();
Class returnType = ((MethodSignature) signature).getReturnType();
来源:https://stackoverflow.com/questions/28092800/when-using-spring-aoparound-how-can-i-get-return-type-of-the-pointcut-method