使用BeanUtis.copyProperties 只能复制对象不可以复制list

BeanUtils.copyProperties(要转换的类, 转换后的类);

List<studentDao> studDao = new ArrayList<studentDao>();

List<student> list = studentService.list();

list.forEach(stu ->{

studentDao userVO = new studentDao();

BeanUtils.copyProperties(stu, userVO);

studDao.add(userVO); });

先将要转换的liat遍历创建要接收的list泛型对象

将遍历的值拷贝到泛型对象中

再add将泛型对象放到实体类中

即可解决

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐