代码:
User user = new User();
try {
BeanUtils.copyProperties(user, register);
} catch (Exception e) {
e.printStackTrace();
error(request, this.getClass(), "类型转换出错");
}
使用BeanUtils工具类提供的方法copyProperties(转换后的对象,要转换的对象);
转换的对象要有get和set方法,使用这个方法能实现对象之间的拷贝,好使!