我有一個數據庫,其中包含所有與日期相關的各種值。我想要做的是返回地圖的日期和與日期相關的所有值的平均值。每次我提出一個要求,我得到如下回應:Spring data jpa - 返回地圖
{
"timestamp": 1473327111738,
"status": 500,
"error": "Internal Server Error",
"exception": "org.springframework.dao.IncorrectResultSizeDataAccessException",
"message": "result returns more than one elements; nested exception is javax.persistence.NonUniqueResultException: result returns more than one elements",
"path": "/dailyAverage"
}
我的代碼:
@Query("SELECT du.date, avg(du.usage) FROM DataUsageModel du WHERE du.date BETWEEN :start_time AND :end_time GROUP BY day(du.date)")
Map<String, Double> findDailyAverages(@Param("start_time") LocalDateTime startTime, @Param("end_time") LocalDateTime endTime);
嘗試使List