Spring Data JPA 分页
程序员文章站
2022-04-25 11:17:01
...
最近在使用Spring Boot 做项目时遇到了关于Spring Data JPA的分页问题,在下面这位大兄弟的博客中有代码实现
LINK: 博客链接
DAO接口:
package com.demo.sell.repository;
import com.demo.sell.entity.OrderMaster;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
public interface OrderMasterRepository extends JpaRepository<OrderMaster,String> {
Page<OrderMaster> findByBuyerOpenid(String buyerOpenid,Pageable pageable);
}
单元测试:
package com.demo.sell.repository;
import com.demo.sell.entity.OrderMaster;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.*;
@SpringBootTest
@RunWith(SpringRunner.class)
public class OrderMasterRepositoryTest {
@Autowired
private OrderMasterRepository orderMasterRepository;
@Test
public void findByBuyerOpenid() {
Page<OrderMaster> byBuyerOpenid = orderMasterRepository.findByBuyerOpenid("001", new PageRequest(0, 5));
List<OrderMaster> content = byBuyerOpenid.getContent();
System.out.println(Arrays.asList(content));
}
}
上一篇: Spring Data JPA 分页
下一篇: 2020-08-25
推荐阅读
-
Spring-Data-JPA整合MySQL和配置的方法
-
Spring Data JPA例子代码[基于Spring Boot、Mysql]
-
Spring Data JPA学习
-
Angular+Bootstrap+Spring Boot实现分页功能实例代码
-
Springboot整合Spring Data Jpa
-
浅谈jpa、hibernate与spring data jpa三者之间的关系
-
jpa分页
-
Spring Data ElasticSearch基本使用
-
bootstrap-table实现服务器分页的示例 (spring 后台)
-
Spring data JPA 多表联合分页查询 自定义实体类