-
根据字符串设置对象对应属性
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; }
Java根据字符串get及set对象对应属性
最新推荐文章于 2023-03-29 10:28:30 发布