mongotemplate分页查询

        Document queryObject = new Document();
        queryObject.put("projectId", vo.getProjectId());

        if(StringUtils.isNotEmpty(vo.getOriginString())){
            queryObject.put("originString", vo.getOriginString());
        }
        if(Objects.nonNull(vo.getFileId())){
            queryObject.put("fileId", vo.getFileId());
        }

        Document fieldsObject = new Document();
        fieldsObject.put("id", true);
        fieldsObject.put("originString", true);
        fieldsObject.put("context", true);

        Query query = new BasicQuery(queryObject, fieldsObject);
        query.with(Sort.by(Sort.Direction.DESC, "createTime"));
        query.skip(vo.getPageSize()*(vo.getPageIndex()-1)).limit(vo.getPageSize());
        List rows = mongoTemplate.find(query,TranStringMGDO.class,TablesUtils.TRAN_STRING);
        long count = mongoTemplate.count(query, TranStringMGDO.class, TablesUtils.TRAN_STRING);

 

你可能感兴趣的:(mongotemplate分页查询)