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