自定义注解:
```java
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* 模型转换设定
*/
@Retention(RetentionPolicy.RUNTIME)
@Target( { ElementType.FIELD })
public @interface TransferSetting {
/**
* 字段类型
*/
public enum FieldType {COMMON, CODE};
/**
* 源字段名
* @return
*/
String originalFieldName();
/**
* 字段类型(默认为COMMON)
* 为Code时需要设定CodeGroup(代码组)属性,根据CodeGroup获取名称后设置到目标Field
* @return
*/
FieldType fieldType() default FieldType.COMMON;
/**
* 代码组
* @return
*/
String codeGroup() default "";
}
```
使用:
```java
// 获取目标类型的转换设定注解
TransferSetting transferSetting = targetField.getAnnotation(TransferSetting.class);
String originalFieldName = "";
if (transferSetting != null && !transferSetting.originalFieldName().isEmpty()) {
originalFieldName = transferSetting.originalFieldName();
} else {
originalFieldName = targetField.getName();
}
```