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

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

问题描述

我最近开始使用Spring data jpa.

I recently started working with Spring data jpa.

如果有人可以对 Spring Data JPA的 findFirst 之间的 技术差异 有所了解,那将是非常有意义的>和 findTop .

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

差异,用法.

谢谢

推荐答案

来自可以通过关键字 first top 限制查询方法的结果,这些关键字可以互换使用.可以将一个可选数值附加到 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天全站免登陆