zhaoxian vor 11 Monaten
Ursprung
Commit
543c1fa596

+ 25 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/TestController.java

@@ -46,6 +46,9 @@ import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.util.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.data.mongodb.core.query.Criteria;
+import org.springframework.data.mongodb.core.query.Query;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
@@ -1881,4 +1884,26 @@ public class TestController {
         refreshTokenService.getLiveKuaiShouAgentRefresh();
     }
 
+    public void save() {
+        JSONObject people = new JSONObject();
+        people.put("_id","zhao");
+        people.put("name","an");
+        mongoTemplate.save(people);
+        JSONObject people2 = new JSONObject();
+        people2.put("_id","yu");
+        people2.put("name","meng");
+        mongoTemplate.save(people2);
+        log.info("save ok");
+    }
+
+    public void find() {
+        Criteria criteria = new Criteria();
+        criteria = Criteria.where("name").is("an");
+        Query query = new Query(criteria);
+        List<JSONObject> list = mongoTemplate.find(query, JSONObject.class);
+        List<JSONObject> all = mongoTemplate.findAll(JSONObject.class);
+        System.out.println("条件筛选结果:" + list);
+        System.out.println("----All结果:" + all);
+        log.info("find ok");
+    }
 }

+ 11 - 0
jeecg-boot-module-system/src/main/resources/application-dev.yml

@@ -158,6 +158,17 @@ spring:
       shutdown-timeout: 100ms
     password: ''
     port: 6379
+  # mongodb 配置
+  data:
+    mongodb:
+      host: 192.168.0.99
+      port: 27017
+      #root:只在admin数据库中可用。超级账号,超级权限
+      username: root
+      password: hcst2024..
+      database: admin
+      authentication-database: admin
+
 #mybatis plus 设置
 mybatis-plus:
   mapper-locations: classpath*:org/jeecg/modules/**/xml/*Mapper.xml,classpath*:cn/com/ctop/**/xml/*Mapper.xml

+ 10 - 1
module-common/pom.xml

@@ -117,7 +117,16 @@
             <artifactId>elasticsearch</artifactId>
             <version>7.6.1</version>
         </dependency>
-
+        <!--mongodb-->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-mongodb</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.mongodb</groupId>
+            <artifactId>mongodb-driver-sync</artifactId>
+            <version>4.10.2</version>
+        </dependency>
     </dependencies>