zoukankan      html  css  js  c++  java
  • 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;
        }
  • 相关阅读:
    Vue.js-项目目录结构解析
    Vue.js-创建Vue项目(Vue项目初始化)并不是用Webstrom创建,只是用Webstrom打开
    Node.js-npm安装包目录修改
    Node.js-Webstorm2018配置nodejs
    Node.js-ReferenceError: _filename is not defined
    cas系列-自定义异常提示(五)
    cas系列-cas登出(四)
    cas系列-cas REST协议(三)
    maven引入第三方jar包
    持续api管理翻译
  • 原文地址:https://www.cnblogs.com/lshan/p/11532941.html
Copyright © 2011-2022 走看看