小编use*_*708的帖子

JSONObject到Document

嗨,我是mongodb的新手,我想将JSONObject转换为Document,然后将其存储到mongodb.这是我编码的内容.我在json中获得了一个服务api.

CloseableHttpResponse response = httpClient.execute(get);
        HttpEntity entity = response.getEntity();          
        JSONObject Rat = new JSONObject(EntityUtils.toString(entity));
Run Code Online (Sandbox Code Playgroud)

然后我想将这个鼠保存为mongodb文件,然后将其插入mongodb或mysql,以便我以后可以显示它.我觉得有点像

Document  doc = new Document(....);
coll.insertOne(doc); /*where coll is 
MongoCollection<Document> coll = db.getCollection("rates"); */
Run Code Online (Sandbox Code Playgroud)

但是如何从JSONObject转换为Document呢?

java json mongodb

8
推荐指数
2
解决办法
1万
查看次数

摆动Mvc模型

我尝试用Swing创建一个MVC应用程序.我对实施以及应该如何应对感到困惑.我的意思是:

  1. 我有Gui这是视图所有逻辑发送到一个名为控制器的类,我有一个模型,我有模型属性.(我读过MVC就是这样)

  2. 我在视图中创建了一些随机代码,输入了我想要的代码数量,并将其转移ActionListener到类命名控制器.使用方法中控制器类上的按钮生成的随机代码.生成随机代码,然后我想将它们保存在数据库中.我很困惑如何在数据库上保存生成的代码.我应该在类命名控制器中创建一个方法,以便我可以从那里保存它们?或另一个与保存更新的不同类查找..........方法?如果是,那么为什么我用Model属性创建Model类?我怎样才能使用Model类.如果我必须使用它,或者我只需要拥有这个类就可以了解如何使用Model类.Model类的用途是什么,只有它与属性一起存在并保存在其他地方?通常使用什么方法,以便我可以使用MVC模式?我很困惑吗?任何帮助我忘了告诉我使用Hibernate.谢谢ps.我也读过这个 http://java.sun.com/products/jfc/tsc/articles/architecture/, 但我不明白.

    public class code(){// this is the Model
        private int i;
        public void setter(int i){
            this.i=i;
        }
    
        public int getter(){
            return i;
        }
    
        public String generateStringInt() {
            return new BigInteger(190, random).toString(32);
        }
    
        // what ever i want to create with the int i variable i will do it on this class?
        ///then i will pass it on the controller to sent it on the view  
        //OR save if i want to save it.?Is this …
    Run Code Online (Sandbox Code Playgroud)

java swing

3
推荐指数
1
解决办法
486
查看次数

标签 统计

java ×2

json ×1

mongodb ×1

swing ×1