刚开始试遍历content,进行转换,添加到新的list中,再set进去page。后来发现page没有提供setContent方法。 后来发现page有个map方法,看了下源码介绍,试了下可以。 之前写法:
Specification<ProcessFormView> pageSpecification = builder.generateSpecification(); Page<ProcessFormView> page= processFormViewRepository.findAll(pageSpecification,pageable); List<ProcessFormView> content = page.getContent(); List<ProcessFormDto> collect = content.stream().map(processFormView -> { ProcessFormDto processFormDto = new ProcessFormDto(); BeanUtils.copyProperties(processFormView, processFormDto); return processFormDto; }).collect(Collectors.toList()); page.setContent(); // 没有set方法 return page;改造后:
Specification<ProcessFormView> pageSpecification = builder.generateSpecification(); Page<ProcessFormView> page= processFormViewRepository.findAll(pageSpecification,pageable); page.map(processFormView -> { ProcessFormDto processFormDto = new ProcessFormDto(); BeanUtils.copyProperties(processFormView,processFormDto); return processFormDto; }); return page;