Chapter II-spring Boot SPRINGDATAJPA Rapid development of the DAO layer, JUnit test

Source: Internet
Author: User
Tags spring initializr

First, Introduction

The first chapter introduces the spring boot simple Introduction, this chapter describes how to quickly implement DAO layer development through SPRINGDATAJPA.

Second, the environment

1. jdk1.8
2. Springboot 1.5.9.RELEASE
3. Apache Maven (3.5.0)
4. Development tools (IntelliJ idea)

Third, step

1) Create a project with idea file->new project->spring initializr, select Web->web,sql->jpa, MySQL.

2) Create the project, modify the Pom to rely on the Springboot 1.5.9.RELEASE (this is my common version, can be modified), add Druid database connection pool, spring boot is through a variety of starter+ Autoconfiguration helps us simplify the configuration.

  

    <Dependencies>        <!--Database Connection Pool -        <Dependency>            <groupId>Com.alibaba</groupId>            <Artifactid>Druid</Artifactid>            <version>1.0.25</version>        </Dependency>        <Dependency>            <groupId>Org.springframework.boot</groupId>            <Artifactid>Spring-boot-starter-data-jpa</Artifactid>        </Dependency>        <Dependency>            <groupId>Org.springframework.boot</groupId>            <Artifactid>Spring-boot-starter-web</Artifactid>        </Dependency>        <Dependency>            <groupId>Mysql</groupId>            <Artifactid>Mysql-connector-java</Artifactid>            <Scope>Runtime</Scope>        </Dependency>        <Dependency>            <groupId>Org.springframework.boot</groupId>            <Artifactid>Spring-boot-starter-test</Artifactid>            <Scope>Test</Scope>        </Dependency>    </Dependencies>

3) Entity classes, JPA interfaces, test classes, configuration files.

Note the need to give a default constructor method

  

    

Through this test case, we simply simulated the JPA add, delete, change, check function, and then associated query, the specified field query is also supported, here do not introduce too much, need to print SQL in the configuration file to open the Showsql property is true, as the result of the run.

Iv. Summary

Through the SPRINGDATAJPA let us feel the development of the DAO layer of convenience, interested can study some complex usage, before we usually use the heavy SQL mode, a lot of business logic is put in a SQL to help us achieve, encounter complex SQL tuning will become very troublesome, With JPA we can try the form of light SQL heavy Java code.

Source Address https://github.com/binary-vi/binary.github.io/tree/master/SpringBoot-demo/demo02

Chapter II-spring Boot SPRINGDATAJPA Rapid development of the DAO layer, JUnit test

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.