Field[] fields = xxxx.class.getDeclaredFields(); // 获取实体类的所有属性,返回Field数组
fields[0].setAccessible(true );
field.getName(); // 获取字段名称
field.get("fieldName"); // 获取字段值
注:
1、setAccessible:
Set the accessible flag for this object to the indicated boolean value. A value of true indicates that the reflected object should suppress Java language access checking when it is used. A value of false indicates that the reflected object should enforce Java language access checks.
First, if there is a security manager, its checkPermission method is called with a ReflectPermission("suppressAccessChecks") permission.
A SecurityException is raised if flag is true but accessibility of this object may not be changed (for example, if this element object is a Constructor object for the class Class).
A SecurityException is raised if this object is a Con
最后
以上就是坚定大侠最近收集整理的关于java获取对象所有属性_获取一个 Object 对象的所有属性的全部内容,更多相关java获取对象所有属性_获取一个内容请搜索靠谱客的其他文章。
发表评论 取消回复