Spring-data is a collection of projects that covers the sub-projects that access a variety of data sources, such as relational, non-relational, etc.
- Spring Data JPA Relationship type
- Spring Data MONGO DB
- Spring Data Redis
- Spring data solr Full-text search, based on Lucene
- Other
Manipulating the database using the raw JDBC approach
1) Creating a MAVEN project
The directory structure of the MAVEN project
Add dependency
<Dependency> <groupId>Mysql</groupId> <Artifactid>Mysql-connector-java</Artifactid> <version>5.1.38</version></Dependency>
2) Database Preparation
3) Develop Jdbcutil tool class
Get connection, close connection,statement, resultset and other resources.
The configuration content is placed in the configuration file, and then the content in the configuration file is referenced through code.
4) Build the object model, Dao
Manipulating the database using spring JDBC
1) Add dependency
<Dependency> <groupId>Org.springframework</groupId> <Artifactid>Spring-jdbc</Artifactid> <version>4.3.5.RELEASE</version> </Dependency> <Dependency> <groupId>Org.springframework</groupId> <Artifactid>Spring-context</Artifactid> <version>4.3.5.RELEASE</version> </Dependency>
2) configuration Beans.xml
3) Develop the spring JDBC version of the query and save method
The disadvantages of accessing the database in the two traditional ways are as follows:
1) Large number of code in DAO
2) DAO implements duplicate code more
3) Paging and other functions need to be developed separately
Download Source codes: Https://pan.baidu.com/s/1eSPFTHS
Srping-data Learning Note One (traditional way to access database implementation and malpractice analysis)