jongo_对表中时间字段进行范围查询

     DB db = DbManager.getInstance().getDataDb();
        Jongo jongo = new Jongo(db);
        MongoCollection sysLogs = jongo.getCollection("sys_logs");

        Map<String, Object> map = new HashMap<>();

        Criteria criteria = new Criteria();
        try {
             SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
             Date start = simpleDateFormat.parse(startTime);
             Date end = simpleDateFormat.parse(endTime);
             criteria.and("handleTime").gte(10l).lte(10000000000000l);

         } catch (ParseException e) {
             e.printStackTrace();
         }
        
if (Objects.nonNull(username)) {
           // map.put("username", username);
            criteria.and("username").equals(username);
        }

        String query = new org.springframework.data.mongodb.core.query.Query(criteria).getQueryObject().toJson();

        MongoCursor<Map> as = sysLogs.find(query).skip((pagination.getCurrent() - 1) * pagination.getPageSize())
                .limit(pagination.getPageSize()).as(Map.class);

 

posted @ 2020-03-04 08:21  忧伤还是快乐EL  阅读(302)  评论(0编辑  收藏  举报