我知道this https://stackoverflow.com/questions/24170972/pageable-and-param-in-a-spring-data-jparepository-method-issue问题,但使用org.springframework.data:spring-data-jpa:1.7.0.RELEASE
我仍然遇到同样的问题(Either use @Param on all parameters except Pageable and Sort typed once, or none at all!
)。我的班级是:
public interface BalanceHistoryRepository extends JpaRepository<BalanceHistory, Long> {
@Query("select bh from BalanceHistory bh where bh.account.id = :idAccount")
public BalanceHistory findCurrentBalanceByAccountNumber(PageRequest pageCriteira, @Param("idAccount") long idAccount);
}
Edit
Call:
Pageable page = new PageRequest(0, 1, Sort.Direction.DESC, "date");
BalanceHistory bh = balanceHistoryRepository.findCurrentBalanceByAccountNumber(1,page);
Method:
@Query("select bh from BalanceHistory bh where bh.account.id = :idAccount")
public BalanceHistory findCurrentBalanceByAccountNumber(@Param("idAccount") long idAccount, Pageable pageCriteira);
确保您使用Pageable
代替PageRequest
以便第一个参数被识别为不绑定到实际查询的参数。此外,您需要将返回类型更改为Page
or List
因为您大多会返回多个结果。
public interface BalanceHistoryRepository extends CrudRepository<BalanceHistory, Long> {
@Query("select bh from BalanceHistory bh where bh.account.id = :idAccount")
Page<BalanceHistory> findCurrentBalanceByAccountNumber(@Param("idAccount") long idAccount, Pageable pageable);
}
这应该可以解决问题。请注意,我们通常建议not扩展商店特定的接口,因为它们公开了商店特定的 API,只有在真正必要时才应公开这些 API。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)