BeanUtils.copyProperties用法

发布时间 2023-09-16 17:56:10作者: 成佛在西天
// 获取 ActionForm 表单数据
UserActionForm uForm = (UserActionForm) form;
// 构造一个User对象
User user = new User();
// 赋值(部分  ==》 整体)
BeanUtils.copyProperties(uForm,user);

注意点

  1、UserActionForm ==》User:部分到整体;

  2、如果User和UserActionForm 间存在名称不相同的属性,则BeanUtils不对这些属性进行处理,需要手动处理;

  3、慎用BeanUtils.copyProperties;若属性较少,则建议直接Get/Set

 

参考文章

【1】https://blog.csdn.net/Mr_linjw/article/details/50236279