//通过class实例化User对象 User u = User.class.newInstance();
//用反射获取所有的域(包括私有的) Field[] fs = User.class.getDeclaredFields(); for(Field f:fs){ //因为User的name是private的 //若不将可访问设为私有,会抛出[can not access a member of class annotation.User with modifiers "private"]的异常 f.setAccessible(true); f.set(u, "test");//这里就给每bean的每个成员都赋值test }