尝试将第一个Java类的值传递给第二个Java类
这个问题在这里已经有了答案:
返回新状态(“成功”,cursor.toString());
您正在返回cursor.toString(),它是游标的字符串表示形式,它不会读取游标的内容,而是像您在循环中使用cursor.next()一样。
创建状态列表并将状态逐一添加到此列表中并返回列表,请参阅以下代码:
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/45593.html
上一篇: Trying to pass the value from first java class to second java class
下一篇: How to make response 404 without any HTML body for RESTful?