spring-boot 使用Pageable将查询结果list 转page 分页
spring-boot
spring-projects/spring-boot: 是一个用于简化Spring应用开发的框架。适合用于需要快速开发企业级Java应用的项目。特点是可以提供自动配置、独立运行和内置的Tomcat服务器,简化Spring应用的构建和部署。
项目地址:https://gitcode.com/gh_mirrors/sp/spring-boot

·
1、通过pageable 实现将list 转 page
测试发现 直接 通过 new pageImpl 来转换page 行不通
Page<String> stringPage = new PageImpl<String>(strings, pageable, strings.size());
根据结果可知 未实现分页功能。
则通过手动分割方式去实现
public static void main(String[] args) {
List<String> strings = new ArrayList<String>();
for (int i=0;i<20;i++){
strings.add("第"+i+"数据");
}
Pageable pageRequest = new PageRequest(1, 10);
Page<String> strings1 = listConvertToPage1(strings, pageRequest);
System.out.println(strings1);
}
public static <T> Page<T> listConvertToPage1(List<T> list, Pageable pageable) {
int start = pageable.getOffset();
int end = (start + pageable.getPageSize()) > list.size() ? list.size() : (start + pageable.getPageSize());
return new PageImpl<T>(list.subList(start, end), pageable, list.size());
}




spring-projects/spring-boot: 是一个用于简化Spring应用开发的框架。适合用于需要快速开发企业级Java应用的项目。特点是可以提供自动配置、独立运行和内置的Tomcat服务器,简化Spring应用的构建和部署。
最近提交(Master分支:17 天前 )
1cd14c96
Prior to this commit, Spring Boot would use Framework's
`Jackson2ObjectMapperBuilder` to configure the `ObjectMapper` instance.
This builder would configure the `ProblemDetail` mixin automatically.
With the introduction of Jackson 3.x support, Spring Framework removed
its builder in favor of the native Jackson builder. As a result, the
mixin is not registered with the `JsonMapper` aymore.
This commit ensures that the mixin is registered if the `ProblemDetail`
class is present in the classpath.
Closes gh-47298
1 天前
51b606e9 - 1 天前
更多推荐
所有评论(0)