美文网首页程序员
简单快捷的在SpringBoot中整合mongodb(只需三步)

简单快捷的在SpringBoot中整合mongodb(只需三步)

作者: 陈金泽 | 来源:发表于2019-03-24 11:20 被阅读0次

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
关注赞赏我:更新更多框架搭建内容!你们的坑我来跳,帮你规避百度上的那些问题教程!

相关文章

网友评论

    本文标题:简单快捷的在SpringBoot中整合mongodb(只需三步)

    本文链接:https://www.haomeiwen.com/subject/edayvqtx.html