Pagelt;gt; vs Slicelt;gt; when to use which?(页面lt;gt;与切片lt;gt;什么时候用哪个?)
问题描述
我读过 Spring Jpa Data 文档 当您分页"从存储库中生成的动态查询时,有关两种不同类型的对象.
I've read in Spring Jpa Data documentation about two different types of objects when you 'page' your dynamic queries made out of repositories.
页面和切片
Page<User> findByLastname(String lastname, Pageable pageable);
Slice<User> findByLastname(String lastname, Pageable pageable);
所以,我试图找到一些文章或任何东西来讨论两者的主要区别和不同用法,性能如何变化以及排序strong> 影响这两种类型的查询.
So, I've tried to find some articles or anything talking about main difference and different usages of both, how performance changes and how sorting affercts both type of queries.
有没有人拥有这类知识、文章或一些好的信息来源?
Does anyone has this type of knowledge, articles or some good source of information?
推荐答案
Page 扩展 Slice 并通过触发计数查询来了解可用元素和页面的总数.来自 Spring Data JPA 文档一个>:
Page 知道可用元素和页面的总数.它通过基础设施触发计数查询来计算总数来实现这一点.由于根据所使用的商店,这可能会很昂贵,因此 Slice 可以用作返回.Slice 只知道是否有下一个 Slice 可用,这在遍历更大的结果集时可能就足够了.
A
Pageknows about the total number of elements and pages available. It does so by the infrastructure triggering a count query to calculate the overall number. As this might be expensive depending on the store used,Slicecan be used as return instead. ASliceonly knows about whether there’s a nextSliceavailable which might be just sufficient when walking through a larger result set.
这篇关于页面<>与切片<>什么时候用哪个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:页面<>与切片<>什么时候用哪个?
基础教程推荐
- 在springboot中如何给mybatis加拦截器 2023-04-29
- 将 double 转换为 Int,向下舍入 2022-01-01
- 将 Windows 证书导入 Java 2022-01-01
- Java ECDSAwithSHA256 签名长度不一致 2022-01-01
- 在java中使用xpath和selenium解析HTML表格数据 2022-01-01
- 如何在相机中应用自定义滤镜 [Surfaceview 预览]. 2022-01-01
- JPA惰性列表上的流 2022-01-01
- Maven:无效的目标版本:10 2022-01-01
- 控制台应用程序中的 Java 键盘输入解析 2022-01-01
- doFilter()是在servlet的工作完成之前还是之后执行的? 2022-01-01
