设置Java Bean属性值
//package com.nowjava;/* from 时代Java - nowjava.com*/ import java.lang.reflect.Field; public class Main { public static void setValues(String[] fields, Object bean, Object[] values) { for (int i = 0; i < fields.length; i++) { setValue(fields[i], bean, values[i]); } } public static void setValue(String field, Object bean, Object value) { try { Field f = bean.getClass().getDeclaredField(field); boolean b = f.isAccessible(); f.setAccessible(true); /** 来自 N o w J a v a . c o m - 时 代 Java**/ f.set(bean, value); f.setAccessible(b); } catch (IllegalAccessException e) { e.printStackTrace(); }