java 中,属性相近的两个对象可以使用BeanUtils.copyProperties()函数对对象进行转换。
下侧代码中LeagueForm是一个表单验证对象,需要将LeagueForm转换为League对象进行添加数据操作。
public League convert(LeagueForm leagueForm) throws Exception {
League league = new League();
BeanUtils.copyProperties(leagueForm, league);
return league;
}
本文介绍如何在Java中利用Apache Commons Lang库的BeanUtils.copyProperties()方法将一个对象的属性复制到另一个对象中。具体示例展示了LeagueForm表单验证对象如何被转换成League业务对象。
2167

被折叠的 条评论
为什么被折叠?



