[Crazy God Mybatis] 1. Introduction to Mybatis

Mybatis-9.28

surroundings:

  • JDK1.8
  • Mysql 5.7
  • maven 3.6.1
  • IDEA

review

  • JDBC
  • Mysql
  • Java basics
  • Maven
  • Junit

SSM framework: The best way to configure files, official documents.

Introduction to Mybatis

1. What is Mybatis

  • MyBatis is an excellent persistence layer framework;
  • It supports custom SQL, stored procedures, and advanced mapping.
  • MyBatis eliminates almost all JDBC code and the work of setting parameters and obtaining result sets.
  • MyBatis can configure and map primitive types, interfaces and Java POJOs (Plain Old Java Objects) as records in the database through simple XML or annotations.
  • MyBatis was originally an open source project iBatis of Apache . In 2010, this project was migrated from apache software foundation to [google code](https://baike.baidu.com/item/google code/2346604), and was renamed MyBatis.
  • Migrated to Github in November 2013 .

How to get Mybatis

  • maven warehouse:
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
<dependency>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis</artifactId>
    <version>3.5.3</version>
</dependency>

2, endurance

Data persistence

  • Persistence is the process of transforming program data in a persistent state and a transient state
  • Memory: Lost when power is off
  • Database (Jdbc), io file persistence.
  • Life: refrigerated, canned

Why do we need persistence

  • Memory is expensive
  • Power loss is lost, need to save

3. Persistence layer

Dao layers

  • The code block to complete the persistence work
  • Clear layer boundaries

4. Why Mybatis

  • Help programmers save data to database.
  • Traditional JDBC code is too complicated. simplify.
  • Frame: A piece of resume paper gives you a form frame instead of a blank sheet of paper for you. You only need to fill in the form frame instead of starting from the blank paper.
  • It does not need Mybatis. It's easier to use.
  • advantage
    • Simple and easy to learn: itself is small and simple. Without any third-party dependencies, the simplest installation is only two jar files + configuration of several sql mapping files. It is easy to learn and easy to use. Through documentation and source code, you can fully grasp its design ideas and implementation.
    • Flexible: Mybatis does not impose any influence on the existing design of the application or database. sql is written in xml, which is convenient for unified management and optimization. All the requirements for operating the database can be met through the sql statement.
    • Uncoupling SQL and program code: By providing a DAO layer, business logic and data access logic are separated, making the system design clearer, easier to maintain, and easier to unit test. The separation of sql and code improves maintainability.
    • Provide mapping tags, support object and database orm field relationship mapping
    • Provide object-relational mapping tags, support object-relationship formation and maintenance
    • Provide xml tags, support writing dynamic sql

Guess you like

Origin blog.csdn.net/hhb442/article/details/112864981