This guide will guide you through the creation of an application that accesses document-based data through a restful front-end based on Hypermedia.
What will you build?
you'll build a spring application that lets you using spring Data REST Create and retrieve Person对象存储在MongoDB NoSQL数据库中
. Spring Data Rest takes Spring HATEOAS and the Spring Data MongoDB features and automatically group them together.
Environmental dependency
Introduce spring-boot-starter-data-mongodb dependencies in the Pom file:
<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>
Create a domain object
Create a new domain object to render a single person.
PackageHello;Importorg.springframework.data.annotation.Id; Public classPerson {@IdPrivateString ID; PrivateString FirstName; PrivateString LastName; PublicString Getfirstname () {returnFirstName; } Public voidsetfirstname (String firstName) { This. FirstName =FirstName; } PublicString Getlastname () {returnLastName; } Public voidsetlastname (String lastName) { This. LastName =LastName; }}
Reference: Accessing MongoDB Data with REST
Using rest to access MongoDB data