设置Java Bean属性值
//package com.nowjava; import java.lang.reflect.Field; /* 来自 *nowjava.com - 时代Java*/ public class Main { public static void setValue(String field, Object bean, Object value) { try { Field f = bean.getClass().getDeclaredField(field); boolean b = f.isAccessible(); f.setAccessible(true); f.set(bean, value); f.setAccessible(b); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace();//N o