BeanUtils.copyProperties 的使用
BeanUtils.copyProperties
可以用于更新,将源数据更新到目标数据中
import org.springframework.beans.BeanUtils;
public Result updatePostgraduate(@RequestBody EasPostgraduate easPostgraduate) {
EasPostgraduate oldPostgraduate = easPostgraduateService.getById(easPostgraduate.getId());
BeanUtils.copyProperties(easPostgraduate, oldPostgraduate); easPostgraduateService.updateById(oldPostgraduate);
}
// 集合类需要遍历复制
List<Company> companies = companyMapper.selectList(new QueryWrapper<Company>().lambda().like(name != null
&& !"".equals(name), Company::getName, name) );
List<CompanyInfoVO> companyInfo = new ArrayList<>();
for (Company company : companies) {
CompanyInfoVO companyInfoVO = new CompanyInfoVO();
BeanUtils.copyProperties(company, companyInfoVO);
companyInfo.add(companyInfoVO);
}
约 3607 字