/**
     * 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()等

相关文章:

  • 2022-12-23
  • 2021-10-25
  • 2021-06-29
  • 2021-09-18
  • 2022-12-23
  • 2022-12-23
  • 2021-10-05
  • 2022-12-23
猜你喜欢
  • 2021-11-21
  • 2022-12-23
  • 2021-07-18
  • 2022-12-23
  • 2021-10-25
  • 2022-02-23
  • 2021-07-20
相关资源
相似解决方案