一、创建项目并导入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
二、相关配置和代码
Application.properites
spring.data.mongodb.host=192.168.21.134
spring.data.mongodb.port=27017
spring.data.mongodb.username=fernfei
spring.data.mongodb.password=520hufei520
spring.data.mongodb.database=fern
spring.data.mongodb.authentication-database=admin
Pojo
Dao
mongo和JPA搭建RESTful风格代码基本一样
可以参照我的JPA搭建RESTful博客