Spring Boot MongoDB simplifies development

Source: Internet
Author: User

Using the @repository interface provided by Springboot, you can accomplish the custom work that once required a lot of code writing and configuration files. These configurations, which previously gave novice programmers a headache and were proud of an experienced programmer, have become less important due to the continuous improvement of the framework and have also improved programmer productivity.

This article describes how to manipulate MongoDB through Springboot.

I. Configure Pom.xml First

<Parent>        <groupId>Org.springframework.boot</groupId>        <Artifactid>Spring-boot-starter-parent</Artifactid>        <version>1.4.1.RELEASE</version>        <RelativePath/> <!--Lookup parent from repository -</Parent>    <Dependencies>        <Dependency>            <groupId>Org.springframework.boot</groupId>            <Artifactid>Spring-boot-starter-web</Artifactid>        </Dependency>        <Dependency>            <groupId>Org.springframework.boot</groupId>            <Artifactid>Spring-boot-starter-tomcat</Artifactid>        </Dependency>        <Dependency>            <groupId>Org.springframework.boot</groupId>            <Artifactid>Spring-boot-starter-data-mongodb</Artifactid>        </Dependency>    </Dependencies>

Two. Configuring the MongoDB configuration in Application.properties

Spring.data.mongodb.uri=mongodb://root:root@localhost:27017/test

Three. Declaration of entity and repository

 @Document (collection = "T_app"  public  class   app{@Id  private   OBJECTID ID; @Field ( "Api_key"  private   String ApiKey;     private   String appname;  private  list<object> activities;}  
@Repository  Public Interface extends Mongorepository<app, objectid>{    App findonebyapikey (String apiKey);}

Four. Supported repository

Ps:keyword can be linked with and methods.

Such as:

list<discountcode> FindFirst5byActivityidinandendtimeafterandStatus (list<objectid> activityids, Date endtime,string status);

Five. Repository Declaration and use

@Autowired Private Apprepository apprepository;

Spring Boot MongoDB simplifies development

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.