Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of page paging that comes with spring boot

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Most people do not understand the knowledge points of this article "how to solve the page paging problem that comes with spring boot", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this article, "how to solve the page paging problem that comes with spring boot".

# page class () springboot included with jpa

Help us paginate.

Public Page findByDetailid (Long id,Pageable pageable)

The first attribute in parentheses indicates the nature of the arrangement, and the second attribute is to save your paging configuration.

In the controller layer @ RequestMapping ("find/ {id} / {page}") public Page getPageComments (@ PathVariable ("id") Long id,@PathVariable ("page") Integer page) {Pageable pageable = new PageRequest (page, 3, Sort.Direction.ASC, "id"); Page ls=commentRepository.findByDetailid (id,pageable); return ls;}

The first parameter indicates the number of pages, the first page starts at 0, and the second parameter contains several pieces of content.

Sort.Direction.ASC indicates that the sorting direction is from small to large, and the last one is the basis for sorting.

In the browser, you can also help us send out the total number of totalElements: 21 totalPages: 7 last:false, and whether the current page is the last page.

# # class selector class='page-numbers' id=pagenum $(".page-numbers") SpringBoot paging query

Some time ago, the company asked to reconstruct the previous code, so the code related to the company's automatic inspection was refactored using the SpringBoot framework. One of the contents encountered in this process is about the paging query function in SpringBoot using JPA. I will list the more important or error-prone configurations, but the rest of the configurations will not be described in detail:

The configuration content of JPA in yml

The figure shows the simple configuration of JPA. It is worth noting that the configuration of properties.hibernate.dialect:org.hibernate.dialect.Oracle10gDialect is the specified database dialect. If it is not configured, the program will run in error.

Interfaces of the DAO layer

Look at the picture. To achieve paging, you must inherit JpaSpecificationExecutor.

Paging query

The above is about the content of this article on "how to solve the page paging problem that comes with spring boot". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more related knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report