1,首先,在pom.xml中添加依赖:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<!--上面这个依赖包含了Spring Data MongoDB的所有必要组件,
下面是Springboot的start-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
2,在 application.properties 或 application.yml 中配置MongoDB连接:
spring.data.mongodb.uri=mongodb://username:password@localhost:27017/my_database
3,然后,例如创建一个实体类User:
该实体类是映射MongoDB集合中的文档。
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.m

最低0.47元/天 解锁文章
2482

被折叠的 条评论
为什么被折叠?



