Spring Data: JPA repository findAll() to return *Map instead of List?

后端 未结 2 1924
臣服心动
臣服心动 2021-02-20 10:12

I have a Spring Data JPA repository interface that looks something like this:

@Repository
public interface DBReportRepository extends JpaRepository

        
2条回答
  •  情歌与酒
    2021-02-20 10:49

    I dont think you will find an easier solution as to create a simple one liner to convert your result to a map. It is simple and fast with java 8 lambdas:

    Map transactionMap = transactionList.stream()
             .collect(Collectors.toMap(Transaction::getId, Function.identity()));
    

提交回复
热议问题