ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
Spring Data JPA 支持使用`first`、`top`以及`Distinct` 关键字来限制查询结果。 ```java public interface UserRepository extends JpaRepository<User, Integer> , JpaSpecificationExecutor<User> { User findFirstByOrderByLastnameAsc(); User findTopByOrderByAgeDesc(); Page<User> queryFirst10ByLastname(String lastname, Pageable pageable); Slice<User> findTop3ByLastname(String lastname, Pageable pageable); List<User> findFirst10ByLastname(String lastname, Sort sort); List<User> findTop10ByLastname(String lastname, Pageable pageable); User findDistinctByUsername(String username); } ``` **** 参考文档:https://docs.spring.io/spring-data/jpa/docs/3.0.8/reference/html/#repositories.limit-query-result