-
根据字符串设置对象对应属性
public static void setAttribute(Object o,String field, Object keyWord) { try { Field f = o.getClass().getDeclaredField(field); f.setAccessible(true); f.set(o, keyWord); } catch (Exception e) { e.printStackTrace(); } }
-
根据字符串获取对象对应属性
public static String getAttribute(Object o,String field) { String r = ""; try { Field f = o.getClass().getDeclaredField(field); f.setAccessible(true); r = f.get(o).toString(); } catch (Exception e) { e.printStackTrace(); } return r; }