本来想在项目里直接用Easy-Trans来做字典翻译,用的时候发现,这个组件不支持原生的mybatis.
于是直接自己写了一个。废话不多说,直接上代码。就两个文件。
import java.lang.annotation.*;
/**
* 字典翻译注解,用于实体类字段自动翻译
*/
@Target(ElementType.FIELD) // 作用于字段
@Retention(RetentionPolicy.RUNTIME) // 运行时生效
@Documented
public @interface DictTrans {
/** 字典key(对应Redis中的字典类型) */
String dictKey();
/** 目标翻译字段名(存储翻译结果的字段) */
String targetField();
}
我这里是直接从redis中取出来进行字典进行翻译
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.geek.common.constant.CacheConstants;
import com.geek.common.core.redis.RedisCache;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.lang.reflect.Field;
import java.util.*;
/**
* 字典翻译切面,自动处理@DictTrans注解的字段翻译
*/
@Aspect
@C

最低0.47元/天 解锁文章
1283

被折叠的 条评论
为什么被折叠?



