Using rest to access MongoDB data

Source: Internet
Author: User
Tags mongodb

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.