BeanWrapper是spring提供的一个用来操作JavaBean属性的工具,他可以直接修改一个类的属性。
public class BeanWrapperTest { public static void main(String[] args) { User user=new User(); BeanWrapper bw= PropertyAccessorFactory.forBeanPropertyAccess(user); bw.setPropertyValue("userName","张三"); System.out.println(user); PropertyValue value=new PropertyValue("userName","李四"); bw.setPropertyValue(value); System.out.println(user); } } public class User { String userName; public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } @Override public String toString() { return "User{" + "userName=‘" + userName + ‘\‘‘ + ‘}‘; } }