根据java反射原理获取java实体字段描述信息
首先是定义一个注解
package com.wonders.framework.annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface CustomTag {
//字段的描述注解
String desc();
}
然后写一个工具类
package com.wonders.framework.annotation;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
public class Parser {
/**
* 通过属性取得属性的描述注解
*
* @param field
* @return
*/
public static String getDesc(Field field) {
String result = null;
try {
field.setAccessible(true);
Annotation[] annotation = field.getAnnotations();
for (Annotation tag : annotation) {
if (tag instanceof CustomTag) {
result = ((CustomTag) tag).desc();
break;
}
}
} catch (SecurityExc