package com.lion.util;import java.lang.reflect.Field;import java.util.ArrayList;import java.util.HashMap;import java.util.Map;/** * * @author liyongyao * */public class GetClassInfo { /** * 获得属性名 * * @param object * @return */ public static ArrayList ComponentsName(Object object) { Field[] fields = object.getClass().getDeclaredFields(); ArrayList filedName = new ArrayList (); for (int i = 0; i < fields.length; i++) { try { String varName = fields[i].getName(); boolean accessFlag = fields[i].isAccessible(); fields[i].setAccessible(true); filedName.add(varName); fields[i].setAccessible(accessFlag); } catch (SecurityException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } } return filedName; } /** * 获取键值对 * * @param object * @return */ public static Map ComponentsNameAndValue(Object object) { Field[] fields = object.getClass().getDeclaredFields(); Map nameAndValue = new HashMap (); ArrayList filedName = new ArrayList (); ArrayList