我是 Spring JPA 的新手。我有一个名为 Product 的模型。我正在尝试编写一个 api 端点来获取产品表的最新记录。
public static interface Repository extends PagingAndSortingRepository<Product, Long>
{
List findTop2ByOrderByIdDesc();
}
当我运行我的应用程序 HAL 浏览器 http://localhost:8080/api/v1/products/search/findTop2ByOrderByIdDesc
我收到错误消息
{
"timestamp": 1440573947629,
"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": "/api/v1/products/search/findTop2ByOrderByIdDesc"
}
如何解决这个问题。好心提醒