从Map <object,object>转换为Map <string,topterminalsdto>

时间:2019-02-10 22:52:41

标签: java spring spring-boot

我想从Rest API终结点返回JSON作为键,并从DB表中获取带有数据的值。示例:

  {
    "terminal 1":
       {"date":"2018-10-06T00:00:00.000+0000","volume":111,"count":1},
    "terminal 2":
       {"date":"2018-11-06T00:00:00.000+0000","volume":122,"count":1}
  }

我试图通过获取表列terminal并将其设置为键来从DB转换结果。但是我得到了错误

@GetMapping("/terminals")
    public ResponseEntity<Map<String, TopTerminalsDTO>> getTopTerminalsVolumes(
            @RequestParam(value = "start_date", required = true) String start_date,
            @RequestParam(value = "end_date", required = true) String end_date) {

            LocalDateTime start_datel = LocalDateTime.now(Clock.systemUTC());
            LocalDateTime end_datel = LocalDateTime.now(Clock.systemUTC());

            final List<PaymentTransactionsDailyFacts> list = dashboardRepository.top_daily_transactions(start_datel, end_datel);

            final Map<String, TopTerminalsDTO> map =
                        list.stream()
                            .collect(Collectors.toMap(dto -> dto.getTerminal(), dto -> dto));



        return ResponseEntity.ok(map);
    }

您知道如何解决错误Type mismatch: cannot convert from Map<Object,Object> to Map<String,TopTerminalsDTO>吗?

0 个答案:

没有答案