Spring Boot MongoDB JPA 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:[email Protected]:27017/test

Three. Declaration of entity and repository

@Document (collection = "T_app") @Datapublic class app{    @Id    private ObjectId Id;    @Field ("Api_key")    private String ApiKey;    Private String appname;    private list<object> activities;}
@Repositorypublic interface Apprepository 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

@Autowiredprivate apprepository apprepository;

Spring Boot MongoDB JPA 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.