import java.lang.reflect.Field;
import java.util. edList;
import java.util.List;
/**
* @Auther: liyue
* @Date: 2018/10/24 14:44
* @De ion:
*/
public class ReflexUtil {
/**
* 获取对象的所有属性值
*
* @param clazzT
* @param <T>
* @return
*/
public static <T> List<String> get AttributeNames(Class<T> clazzT) {
List<String> list = new edList<>();
try {
//根据类名获得其对应的Class对象 写上你想要的类名就是了 注意是全名 如果有包的话要加上 比如java.Lang.String
Class clazz = Class.forName(clazzT.getName());
//根据Class对象获得属性 私有的也可以获得
Field[] fields = clazz.getDeclaredFields();
for (Field f : fields) {
list.add(f.getName());
// 类型
// f.getType();
}
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
/**
* 把对象String类型为空的值设置为\"\"
*
* @param
*/
public static void setNotNull( ) {
try {
for (Field f : .getClass().getDeclaredFields()) {
f.setAccessible(true);
//判断字段是否为空,并且对象属性中的基本都会转为对象类型来判断
if (f.get( ) == null) {
try {
f.set( , \"\");
} catch (Exception e) {
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
END。
继续阅读与本文标签相同的文章
下一篇 :
【总结】进程描述与控制
-
零售电商月销售额高达20+万?小程序分销模式助你一臂之力
2026-05-18栏目: 教程
-
如何让日志说话,让它主动说话
2026-05-18栏目: 教程
-
《Android组件化架构》| 每日读本书
2026-05-18栏目: 教程
-
从零开始入门 K8s | 详解 K8s 容器基本概念
2026-05-18栏目: 教程
-
8年前诞生于淘宝,细数阿里云RPA 的前世今生!
2026-05-18栏目: 教程
