假如一个学生类的list集合,返回50条数据;我只需要该集合中的学生姓名name字段,其他的字段都不想要,那么可以
String gender="男";
List<Student> students = studentMapper.selectListByQuery(QueryWrapper.create()
.where(STUDENT.GENDER.eq(gender)));
List<String> nameList = students.stream().map(Student::getName).collect(Collectors.toList());
//nameList存的全是name字段的值
通过stram流把Student集合转换成StudentAo集合,案例
public R<Page<StudentAo>> sysGetPage(@RequestBody StudentVo vo) {
Page<Student> page = studentService.page(vo.getPage(), vo.giveQuerywrapper());
Page<StudentAo> pageAo =new Page<>();
List<Student> records = page.getRecords();
List<StudentAo> collect = records.stream().map(student -> {
StudentAo ao = new StudentAo();
BeanUtils.copyProperties(student, ao);
return ao;
}).collect(Collectors.toList());
pageAo.setRecords(collect);
pageAo.setPageSize(page.getPageSize());
pageAo.setPageNumber(page.getPageNumber());
pageAo.setTotalPage(page.getTotalPage());
pageAo.setTotalRow(page.getTotalRow());
return R.ok("成功",pageAo);
}