簡單快捷的在SpringBoot中整合mongodb(只需三步)
SpringBoot整合mongodb
部署mongodb
1.新增依賴檔案
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-mongodb --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-mongodb</artifactId> </dependency> <!-- https://mvnrepository.com/artifact/org.mongodb/mongo-java-driver --> <dependency> <groupId>org.mongodb</groupId> <artifactId>mongo-java-driver</artifactId> </dependency>
2.新增配置引數
在application.properties中配置引數
#config mongodb spring.data.mongodb.uri=mongodb://localhost:27017/test
3.使用操作mongodb操作類
在程式碼中注入MongoOperations類來操作mongodb
@Autowired private MongoOperations mongoOperations; public void test(){ Student student = new Student("cjz",24); mongoOperations.save(student); }
關於MongoOperations的操作方法
-------------------------------------------cjz
框架搭建完畢
小白也能快速搭建MyBatis框架,學習框架不入坑!
這裡是spring-boot-demo:
https://pan.baidu.com/s/1jN5udzNr_WUsosPIYvqrew
提取碼:jiml
關注讚賞我:更新更多框架搭建內容!你們的坑我來跳,幫你規避百度上的那些問題教程!