gpt4 book ai didi

java - 如何使用Spring boot jpa 1.11在mysql中实现第一个最大记录

转载 作者:行者123 更新时间:2023-11-29 18:43:04 24 4
gpt4 key购买 nike

我需要应用程序中的最大第一条记录,我正在使用 Spring boot JPA 和 MYSQL 查询,我尝试过,

 @Query("select d from Table where d.StatusType=:StatusType and d.tableNumber< :cuurentTableNumber ORDER BY d.tableNumber DESC  LIMIT 1",nativeQuery = true)
Draw findTop1ByOrderByDrawNumberDesc(@Param("StatusType") Table.StatusType StatusType, @Param("tableNumber")int cuurentTableNumber);


@Query("select d from Table d where d.StatusType=:StatusTypeand d.tableNumber<:cuurentTableNumber")
Draw findTop1ByOrderByDrawNumberDesc(@Param("StatusType") Table.StatusType StatusType, @Param("tableNumber")int cuurentTableNumber , Pageable pageable);

还有其他试验,但很多次都不起作用,它给了我发现多个记录的错误。我只需要一条记录,该记录是 Max 但小于当前数量。

LIMIT 不适用于 JPA,因此无法使用它。

有人知道如何实现这一目标吗?

最佳答案

我通过执行以下操作实现了它,

@Query("select d from Table d where " +
"d.tableNumber <> :tableNumber " +
"and (" +
"(d.statusType = :statusType) " +
") ORDER BY d.TableNumber desc")
Iterable<Table> findPreviousNumber(@Param("tableNumber") int tableNumber,
@Param("statusType") statusType closeStatusType);

仍然会调查为什么这不适用于 findFirst/Top

关于java - 如何使用Spring boot jpa 1.11在mysql中实现第一个最大记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44819163/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com