java 中,属性相近的两个对象可以使用BeanUtils.copyProperties()函数对对象进行转换。
下侧代码中LeagueForm是一个表单验证对象,需要将LeagueForm转换为League对象进行添加数据操作。
public League convert(LeagueForm leagueForm) throws Exception {
League league = new League();
BeanUtils.copyProperties(leagueForm, league);
return league;
}