关于网站开发的毕业设计,黄页网怎么样,网站模板安装教程,金牛区网站建设spring-boot-data-jpa、JPA实现分页
JPA越来越丰富了#xff0c;下面使用springboot3.x实现JPA分页 通过传入PageRequest pageRequest PageRequest.of(page, size);到接口查询#xff0c;返回Page拿到分页数据。 转自 https://lingkang.top/archives/jpa-shi-xian-fen-ye
…spring-boot-data-jpa、JPA实现分页
JPA越来越丰富了下面使用springboot3.x实现JPA分页 通过传入PageRequest pageRequest PageRequest.of(page, size);到接口查询返回Page拿到分页数据。 转自 https://lingkang.top/archives/jpa-shi-xian-fen-ye
依赖 dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-data-jpa/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-security/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependencydependencygroupIdcom.mysql/groupIdartifactIdmysql-connector-j/artifactIdscoperuntime/scope/dependency数据库配置
spring.jpa.show-sqltrue
spring.jpa.open-in-viewfalse
spring.jpa.hibernate.ddl-autoupdate
spring.datasource.driver-class-namecom.mysql.cj.jdbc.Driver
spring.datasource.urljdbc:mysql://localhost:3306/test?useUnicodetruenullCatalogMeansCurrenttruecharacterEncodingutf-8useSSLfalseserverTimezoneAsia/Shanghai
spring.datasource.usernameroot
spring.datasource.password123456
spring.datasource.hikari.maximum-pool-size10
spring.datasource.hikari.poolNamedb1启动类
SpringBootApplication
EnableJpaRepositories(top.lingkang.lingdongmall.repository)
EntityScan(top.lingkang.lingdongmall.entity)
public class LingdongMallApplication {public static void main(String[] args) {SpringApplication.run(LingdongMallApplication.class, args);}}接口
public interface GoodsRepository extends JpaRepositoryGoodsEntity, String {Query(select e from GoodsClassifyEntity c left join GoodsEntity e on e.idc.goodsId where c.classifyId?1 and c.level?2)PageGoodsEntity goods(String classifyId, String level, Pageable pageable);
}调用 public ResponseResultPage goods(String classifyId, String level, Integer page, Integer size) {// 注意page分页是从0开始计算的0第一页PageRequest pageRequest PageRequest.of(page, size);PageGoodsEntity goods goodsRepository.goods(classifyId, level, pageRequest);return new ResponseResultPage().setPage(page).setSize(size).setTotal(goods.getTotalElements()) // 分页总数.setData(goods.getContent()); // 分页查询到内容}