update 优化 统一补全代码注释

This commit is contained in:
疯狂的狮子Li
2026-03-13 19:36:14 +08:00
parent 916282ba68
commit 48992b574d
201 changed files with 2554 additions and 465 deletions

View File

@@ -10,11 +10,11 @@ import org.dromara.common.translation.annotation.TranslationType;
public interface TranslationInterface<T> {
/**
* 翻译
* 翻译键执行转换。
*
* @param key 需要被翻译的键(不为空)
* @param other 其他参数
* @return 返回键对应的值
* @return 返回键对应的翻译
*/
T translation(Object key, String other);
}

View File

@@ -14,6 +14,14 @@ import java.util.List;
*/
public class TranslationBeanSerializerModifier extends ValueSerializerModifier {
/**
* 为翻译字段补充空值序列化器,确保字段值为 {@code null} 时仍能走翻译处理链。
*
* @param config 当前序列化配置
* @param beanDesc Bean 描述提供者
* @param beanProperties 当前 Bean 的属性写入器列表
* @return 调整后的属性写入器列表
*/
@Override
public List<BeanPropertyWriter> changeProperties(SerializationConfig config, BeanDescription.Supplier beanDesc,
List<BeanPropertyWriter> beanProperties) {

View File

@@ -38,10 +38,23 @@ public class TranslationHandler extends ValueSerializer<Object> {
this.translation = null;
}
/**
* 创建绑定指定翻译注解的序列化处理器。
*
* @param translation 当前字段上声明的翻译注解
*/
public TranslationHandler(Translation translation) {
this.translation = translation;
}
/**
* 将原始字段值翻译为展示值并写回序列化结果。
*
* @param value 原始字段值
* @param gen Json 输出器
* @param ctxt 序列化上下文
* @throws JacksonException Json 序列化异常
*/
@Override
public void serialize(Object value, JsonGenerator gen, SerializationContext ctxt) throws JacksonException {
TranslationInterface<?> trans = TRANSLATION_MAPPER.get(translation.type());
@@ -68,6 +81,13 @@ public class TranslationHandler extends ValueSerializer<Object> {
}
}
/**
* 按字段上的 {@link Translation} 注解创建上下文相关的翻译序列化器。
*
* @param ctxt 序列化上下文
* @param property 当前序列化属性
* @return 存在翻译注解时返回新的翻译处理器,否则沿用默认序列化器
*/
@Override
public ValueSerializer<?> createContextual(SerializationContext ctxt, BeanProperty property) {
Translation translation = property.getAnnotation(Translation.class);

View File

@@ -17,6 +17,13 @@ public class DeptNameTranslationImpl implements TranslationInterface<String> {
private final DeptService deptService;
/**
* 将部门 ID 或 ID 集合翻译为部门名称。
*
* @param key 部门 ID 或逗号分隔的 ID 字符串
* @param other 额外参数
* @return 部门名称
*/
@Override
public String translation(Object key, String other) {
if (key instanceof String ids) {

View File

@@ -18,6 +18,13 @@ public class DictTypeTranslationImpl implements TranslationInterface<String> {
private final DictService dictService;
/**
* 根据字典类型和字典值翻译显示标签。
*
* @param key 字典值
* @param other 字典类型
* @return 字典标签
*/
@Override
public String translation(Object key, String other) {
if (key instanceof String dictValue && StringUtils.isNotBlank(other)) {

View File

@@ -17,6 +17,13 @@ public class NicknameTranslationImpl implements TranslationInterface<String> {
private final UserService userService;
/**
* 将用户 ID 或 ID 集合翻译为用户昵称。
*
* @param key 用户 ID 或逗号分隔的 ID 字符串
* @param other 额外参数
* @return 用户昵称
*/
@Override
public String translation(Object key, String other) {
if (key instanceof Long id) {

View File

@@ -17,6 +17,13 @@ public class OssUrlTranslationImpl implements TranslationInterface<String> {
private final OssService ossService;
/**
* 将 OSS ID 或 ID 集合翻译为访问地址。
*
* @param key OSS ID 或逗号分隔的 ID 字符串
* @param other 额外参数
* @return 访问地址
*/
@Override
public String translation(Object key, String other) {
if (key instanceof String ids) {

View File

@@ -18,6 +18,13 @@ public class UserNameTranslationImpl implements TranslationInterface<String> {
private final UserService userService;
/**
* 将用户 ID 翻译为用户名。
*
* @param key 用户 ID
* @param other 额外参数
* @return 用户名
*/
@Override
public String translation(Object key, String other) {
return userService.selectUserNameById(Convert.toLong(key));