mongo DB分页

参考:https://blog.csdn.net/qq_40715775/article/details/83153808

依赖:

      <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-mongodb</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
        </dependency>

 

domain:

@NoArgsConstructor
@AllArgsConstructor
@Document(collection = Constant.MILESTONE_WORK_TABLE)
public class MilestoneInfo implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    private String id;

    private String mawb;}

 

config:(application.propeties)

#spring.data.mongodb.uri=mongodb://userName:password@ip:port/database
spring.data.mongodb.database=SERVICE-sea-test
spring.data.mongodb.host=127.0.0.1
spring.data.mongodb.port=27017
#spring.data.mongodb.username=root
#spring.data.mongodb.password=root

 

 

repository:

  @RepositoryRestResource(path = "worktable",collectionResourceRel = "worktables")
    public interface WorkTableRepository  extends MongoRepository<MilestoneInfo, String>{
    
//    @Query("{\"sendtimes\":{\"$regex\":?0}, \"courierbillNo\": ?1}")
    List<MilestoneInfo> findByReasonAndCustomerAndSendTimesLessThan(String reason, String customer,int sendTimers);
    
//    @Query("{\"sendtimes\":{\"$regex\":?0}, \"success\": ?1}")
    List<MilestoneInfo> findByMawbOrCustomerOrOrderNoOrStatusOrCourierBillNoOrSendTimesLessThan(String mawb, String customer,String orderNo,String status,String courierbillNo,Integer sendTimers);
   
    
    List<MilestoneInfo> findByMawbAndCustomerAndOrderNoAndStatusAndCourierBillNoAndSendTimesLessThan(String mawb, String customer,String orderNo,String status,String courierbillNo,Integer sendTimers);

}

 

 

 

web:

    @GetMapping("finds/{page}/{size}")
    public Page<MilestoneInfo> findByPageSort(@PathVariable("page")int page,@PathVariable("size")int size) {
        
        
        //Sort sort = new Sort("id");
        Sort sort = new Sort(Direction.ASC,"mawb");
        
//        Pageable接口用于构造翻页查询,PageRequest是其实现类,可以通过提供的工厂方法创建PageRequest:
//        public static PageRequest of(int page, int size)
//        也可以在PageRequest中加入排序:
//        public static PageRequest of(int page, int size, Sort sort)
        
        
        PageRequest pageable =  PageRequest.of(page - 1, size,sort);
        Page<MilestoneInfo> pagedatas = workTableRepository.findAll(pageable);
        return pagedatas;
    }

 

转载于:https://www.cnblogs.com/lshan/p/11532941.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值