Spring Data JPA 的 findFirst 和 findTop 之间的技术差异 [英] Technical differences between Spring Data JPA's findFirst and findTop

查看:115
本文介绍了Spring Data JPA 的 findFirst 和 findTop 之间的技术差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始使用 Spring 数据 jpa.

I recently started working with Spring data jpa.

如果有人能够阐明 技术差异 Spring Data JPA 的 findFirstfindTop.

It would be highly appreciable if somebody could throw some light on the technical differences between Spring Data JPA's findFirst and findTop.

区别,用法.

谢谢

推荐答案

来自 Spring Data JPA - 参考文档

可以通过关键字firsttop来限制查询方法的结果,这两个关键字可以互换使用.一个可选的数值可以附加到 top/first 以指定要返回的最大结果大小.如果忽略数字,则假定结果大小为 1.

The results of query methods can be limited via the keywords first or top, which can be used interchangeably. An optional numeric value can be appended to top/first to specify the maximum result size to be returned. If the number is left out, a result size of 1 is assumed.

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);

限制表达式还支持 Distinct 关键字.此外,对于将结果集限制为一个实例的查询,支持将结果包装到 Optional 中.

The limiting expressions also support the Distinct keyword. Also, for the queries limiting the result set to one instance, wrapping the result into an Optional is supported.

这篇关于Spring Data JPA 的 findFirst 和 findTop 之间的技术差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆