All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hanqunfeng.reactive.redis.cache.aop.AspectSupportUtils Maven / Gradle / Ivy

package com.hanqunfeng.reactive.redis.cache.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.cache.interceptor.SimpleKeyGenerator;
import org.springframework.context.expression.AnnotatedElementKey;
import org.springframework.expression.EvaluationContext;
import org.springframework.util.StringUtils;

import java.lang.reflect.Method;

/**
 * 

自定义注解支持EL表达式

* Created by hanqf on 2020/11/21 19:35. */ public class AspectSupportUtils { private static ExpressionEvaluator evaluator = new ExpressionEvaluator(); public static Object getKeyValue(JoinPoint joinPoint, String keyExpression) { if(keyExpression.contains("#") || keyExpression.contains("'")) { return getKeyValue(joinPoint.getTarget(), joinPoint.getArgs(), joinPoint.getTarget().getClass(), ((MethodSignature) joinPoint.getSignature()).getMethod(), keyExpression); } return keyExpression; } private static Object getKeyValue(Object object, Object[] args, Class clazz, Method method, String keyExpression) { if (StringUtils.hasText(keyExpression)) { EvaluationContext evaluationContext = evaluator.createEvaluationContext(object, clazz, method, args); AnnotatedElementKey methodKey = new AnnotatedElementKey(method, clazz); return evaluator.key(keyExpression, methodKey, evaluationContext); } return SimpleKeyGenerator.generateKey(args); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy