First, create a project and import dependence
<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>
Second, the relevant configuration and code
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
sing
Dao
mongo JPA and RESTful style building codes essentially the same
I can refer to the JPA to build RESTful blog