zoukankan      html  css  js  c++  java
  • Spring Data JPA 分页

    最近在使用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));
        }
    }
  • 相关阅读:
    zookeeper集群搭建
    mysql当前库的查询
    逻辑卷管理
    python小技巧,各种进制的转换
    修剪我的身心
    点击右键很慢,禁用网卡就好了问题解决了(转载)
    实际应用中的C#加密
    ckeditor+ckfinder配置
    ASP.NET MVC学习总结(二)
    MVC3关于用户名的验证
  • 原文地址:https://www.cnblogs.com/sybk/p/10004716.html
Copyright © 2011-2022 走看看