- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要您对分页的建议。
我的表数据很长。因此我使用分页和每个分页操作 © 从数据库调用数据
我在 spring-boot 应用程序中有一个 rest 方法。
此方法可以从数据库中获取数据,一切正常。
我需要页面计数(我的数据的所有计数/每页计数)。
我可以从数据库中找到这个计数。
我必须为 allCount 和下面的方法编写两个单独的方法吗?
如何在 Spring boot 中使用理想的分页方式?
@CrossOrigin(maxAge = 3600)
@RequestMapping(value = "/payment/all", method = RequestMethod.POST)
public List<NotaryPaymentInformationEntity> getAllProduct(@RequestBody PaginationModel pag){
try {
System.out.println(pag.getPageno()+ " " + pag.getRecords());
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Pageable pageable = new PageRequest(pag.getPageno(), pag.getRecords());
System.out.println("here"+notaryPaymentRepository.findAll(pageable).getContent().size());
return notaryPaymentRepository.findAll(pageable).getContent();
}
public interface NotaryPaymentRepository extends JpaRepository<NotaryPaymentInformationEntity,Integer>{
}
最佳答案
您可以在 Page 类 obj 中获得查询的响应,它扩展了 Slice 类并具有您需要的所有方法。
Pageable pageable = new PageRequest(pageNo, PAGE_SIZE);
pageNo和PAGE_SIZE需要从客户端发送
@Query(value = "SELECT h FROM {NameOfYourModelClass} h")
Page<HorseWatch> getPaginatedModel(Pageable pageable);
从您的服务类调用此方法并在 Page 对象中检索它
可以使用(using getContent(),getNumber(),getTotalPages() 来自对象 )
将这些值保存在您的响应类中并将此类发送回客户端
public class PageResponse {
private List<{NameOfModelClass}> content;
private int currentPage;
private int totalPages;
}
关于java - 如何在 Spring Boot 中选择理想的分页方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51097962/
从许多帖子中我可以读到有关最大池大小的公式,它取决于 CPU 的数量 + 1。这是一个明确的解释。 但是如果应用程序定义了许多执行器或线程池执行器怎么办。然后我们还必须考虑应用程序共享相同的硬件。这对
我一直在寻找垂直 Accordion 内容 slider 。我找到了一个:http://www.marghoobsuleman.com/jQuery-common-accordion ,而且还不错。我
在 not having a whole bunch of luck 之后找到任何可充当 SNMP 代理的 .NET SNMP 库(可在 OSS 项目中使用 - 这意味着专有库已经过时),我现在正在考
目前我正在考虑: VMWare 管理程序 ESXi 中央操作系统 5.5 内存缓存 1.4.5和依赖 这就是全部。我还需要什么/任何替代品吗? 最佳答案 Memcached在linux上运行的很好,所
我是一名优秀的程序员,十分优秀!