Trying to pass the value from first java class to second java class

This question already has an answer here:

  • Get value from one class to use it in another class (java) 3 answers

  • return new Status("success", cursor.toString());

    You are returning cursor.toString() which is cursor's string representation, which doesn't read content of cursor rather use cursor.next() as you have used in loop.

    Create list of status and add status into this list one by one and return list, please see below code:

    try {           
    
        //Build the query
        BasicDBObject query = new BasicDBObject();                                              
        query.put("building_Id", building_Id);
        query.put("floor_Id", floor_Id);
    
        DBObject removeIdProjection = new BasicDBObject("_id", 0);
    
        //Provide the query as an argument to the find()
        DBCursor cursor = col.find(query, removeIdProjection);          
        List<Status> statusList = new ArrayList<>(); 
        //Iterate the cursor
        while (cursor.hasNext()) {
            Status status = new Status("success", cursor.next()); 
            statusList.add(status);
        }
    
        return statusList;
    
    } catch(Exception e) {
        e.printStackTrace();
    }
    
    链接地址: http://www.djcxy.com/p/45594.html

    上一篇: Cache之间有什么区别

    下一篇: 尝试将第一个Java类的值传递给第二个Java类