自己买服务器建设网站张家口职教中心计算机网站建设
web/
2025/10/9 11:17:54/
文章来源:
自己买服务器建设网站,张家口职教中心计算机网站建设,18款未成年禁止下载的游戏,百度 搜索到手机网站找网上的资料看了下增删改查#xff0c;等日后补上。已经实现了数据的插入#xff0c;现在想通过 _id属性来查找数据。一开始看到 类似 55b321df715cc162076eb466 这么一长串的内容觉得是string类型。但是发现并不能搜索到结果#xff0c;在网上搜到了解决方案#xff1a;S…找网上的资料看了下增删改查等日后补上。已经实现了数据的插入现在想通过 _id属性来查找数据。一开始看到 类似 55b321df715cc162076eb466 这么一长串的内容觉得是string类型。但是发现并不能搜索到结果在网上搜到了解决方案String sid 55b321df715cc162076eb466;sitem.put(_id, new ObjectId(sid));cursor collection.find(sitem);通过ObjectId类型就可以查找数据了。demo源代码:package persistence;import java.net.UnknownHostException;import java.util.Date;import org.bson.types.ObjectId;import net.sf.json.JSONObject;import com.mongodb.BasicDBObject;import com.mongodb.DB;import com.mongodb.DBCollection;import com.mongodb.DBCursor;import com.mongodb.DBObject;import com.mongodb.Mongo;import domain.Article;public class TestMongo {public static void main(String[] args) {Mongo mongo null;try {// 8908 mongo.duapp.com smbWruErqVUXLgjDDSEGmongo new Mongo(localhost, 27017);System.out.println(connection success);DB db mongo.getDB(myblog);DBCollection collection db.getCollection(article);BasicDBObject item new BasicDBObject();item.put(title, Rectangle Area);item.put(date, new Date());item.put(extract,Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.);String content Assume that the total area is never beyond the maximum possible value of int.这道题求得是两个举行覆盖的面积。如果两个矩形没有相交的话直接返回两个矩形面积之和就可以了如果有重合那么再减去重合的面积即可。在如何计算重合面积上花费了一些时间感觉思维还是有待加强。代码;item.put(content, content);collection.insert(item);String sid 55b321df715cc162076eb466;Object sido new Object();DBCursor cursor collection.find();while (cursor.hasNext()) {// System.out.println(result:cursor.next());DBObject o cursor.next();/** String id (String) o.get(_id).toString(); sido * o.get(_id); System.out.println(id); sid id; String title* (String) o.get(title); System.out.println(title);** Date date (Date) o.get(date);* System.out.println(date.getDate());** String extract (String) o.get(extract);* System.out.println(extract);*/System.out.println(search for id: sid);BasicDBObject sitem new BasicDBObject();sitem.put(_id, new ObjectId(sid));cursor collection.find(sitem);while (cursor.hasNext()) {System.out.println(found result:);System.out.println(cursor.next().get(date).toString());}}} catch (Exception e) {e.printStackTrace();}}}结果
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/89603.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!