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的操作方法
查看此链接
https://blog.csdn.net/yshuoo/article/details/84789788
-------------------------------------------cjz
框架搭建完毕
小白也能快速搭建MyBatis框架,学习框架不入坑!
这里是spring-boot-demo:
https://pan.baidu.com/s/1jN5udzNr_WUsosPIYvqrew
提取码:jiml
关注赞赏我:更新更多框架搭建内容!你们的坑我来跳,帮你规避百度上的那些问题教程!
网友评论