Srping-data Learning Note One (traditional way to access database implementation and malpractice analysis)

Source: Internet
Author: User

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)

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.