BeanUtils.copyProperties()用法

不废话直接上例子,一看就懂.

// 获取UserFrom表单数据
UserFrom userForm = (UserFrom)from;

// 构造一个User对象
User user = new User();

// 赋值
user.setUserName(userFrom.getUserName);
user.setUserAge(userForm.getUserAge);
user.setBirthday(userForm.getBirthday);
......

相当于以下情况.

// 获取UserFrom表单数据
UserFrom userForm = (UserFrom)from;

// 构造一个User对象
User user = new User();

// 赋值
BeanUtils.copyProperties(user,userFrom);