Как исправить «Используя Spring AOP, я хочу изменить возвращаемое значение, но возвращаемый класс не мой метод return» - PullRequest
1 голос
/ 05 июня 2019

Я использую Spring AOP для изменения возвращаемого значения. Но я обнаружил, что возвращаемое значение в функции @Around не является возвращаемым значением метода. Как решить проблему?

Контроллер


Page<Object> page = PageHelper.startPage(pageNo, pageSize, true);
    CallRecordEntity callRecordParam = new CallRecordEntity();
    BeanUtils.copyProperties(callRecordVO, callRecordParam);
    callRecordParam.setEnterpriseId(ThreadCacheMgr.getEntId());
    List<CallRecordEntity> list = callRecordService.callList(callRecordParam);

Услуги

  @Override
  @SensitiveInfo(SensitiveInfoType.CALL_RECORD)
  public List<CallRecordEntity> callList(CallRecordEntity callRecordEntity) {

}
  @Pointcut("@annotation(com.zhexinit.aicc.common.annotation.SensitiveInfo)")
  public void sensitiveInfoAspect() {

  }

 @Around("sensitiveInfoAspect()")
  public Object process(ProceedingJoinPoint point) throws Throwable {
    UserCacheVO userCacheVO = (UserCacheVO) SecurityContextHolder.getContext().getAuthentication()
        .getPrincipal();
    Object ret = point.proceed();
    Signature signature = point.getSignature();
    MethodSignature methodSignature = (MethodSignature) signature;
    Method targetMethod = methodSignature.getMethod();
    System.out.println("classname:" + targetMethod.getDeclaringClass().getName());
    System.out.println("superclass:" + targetMethod.getDeclaringClass().getSuperclass().getName());
    System.out.println("isinterface:" + targetMethod.getDeclaringClass().isInterface());
    System.out.println("target:" + point.getTarget().getClass().getName());
    System.out.println("proxy:" + point.getThis().getClass().getName());
    System.out.println("method:" + targetMethod.getName());
    System.out.println("methodReturnType:" + targetMethod.getReturnType().getName());
    System.out.println("return value:" + ret.getClass().getName());
    return ret;
  }

Я ожидаю, что ret.getClass (). GetName () будет List, но возвращаемое значение - Page в контроллере

...