今天做了第一个任务通过querydsl实现处方实绩的一个日期日次周次月次的取数据功能
- 实现类型转换
List<PrescriptionVO> productResultDTOToVO = productResult.getResults().stream().map(dto -> new PrescriptionVO())
.collect(Collectors.toList());
QueryResults<PrescriptionVO> r = new QueryResults<>(
productResultDTOToVO,
productResult.getLimit(),
productResult.getOffset(),
productResult.getTotal()
);
results = r;*/
//return results == null ? new QueryResults<>(new ArrayList<>(), 0L, 0L, 0L) : results;
简单来说就是通过.stream().map(自定义名称 -> new 要转换的类名()).collect(Collectors.toList());
- .collect:结束Stream流。
- Collectors.toList():类实现了很多归约操作,例如将流转换成集合和聚合元素。Collectors 可用于返回列表或字符串
- steam():把一个源数据,可以是集合,数组,I/O channel, 产生器generator 等,转化成流。
- map():用于映射每个元素到对应的结果。以下代码片段使用 map 输出了元素对应的平方数: