/**
* testok
* entity number->dto number reduce sum
* 第二个dto需要在外层声明
*/
@Test
public void testDTOReduce(){
LoansDTO resultLoansDTO = LoansDTO.builder().build();
LoansDTO loansDTO = loansEntityList.stream()
.map(loansEntity -> LoansDTO.builder()
.loanFirst(loansEntity.getLoanFirst())
.loanSecond(loansEntity.getLoanSecond())
.countSimle(loansEntity.getCountSimle()).build())
.reduce((x, y) -> {
resultLoansDTO.setLoanFirst(x.getLoanFirst().add(y.getLoanFirst()));
resultLoansDTO.setLoanSecond(x.getLoanSecond().add(y.getLoanSecond()));
resultLoansDTO.setCountSimle(x.getCountSimle()+y.getCountSimle());
return resultLoansDTO;
})
.get();
System.out.println(loansDTO);
}
如上所示,第二个计算中DTO不能进行new 或者builder,而只是需要在外层进行先创建声明.否则无法获取结果,执行不到get()或者orElse()等