Understand the mybatis construction process and get started with the first mybatis program

Table of contents

Environmental description:

What is MyBatis

Endurance

persistence layer

Why you need Mybatis


Environmental description:

What is MyBatis

Endurance

Persistence is a mechanism for converting program data between persistent and transient states.

Why do we need persistence services? That is caused by a defect in the memory itself

persistence layer

What is the persistence layer?

Why you need Mybatis

  • jdk 8 +

  • MySQL 5.7.19

  • maven-3.6.1

  • IDEA

  • Basics you need to master before learning:

  • JDBC

  • MySQL

  • Java basics

  • Maven

  • Junit

  • MyBatis is an excellent persistence layer framework

  • MyBatis avoids almost all JDBC code and the process of manually setting parameters and obtaining result sets

  • MyBatis can use simple XML or annotations to configure and map native information, mapping interfaces and Java entity classes [Plain Old Java Objects, ordinary Java objects] into records in the database.

  • MyBatis was originally an open source project ibatis of apache. In 2010, this project was migrated from apache to google code and renamed MyBatis.

  • Migrated to Github in November 2013 .

  • Mybatis official documentation: http://www.mybatis.org/mybatis-3/zh/index.html

  • GitHub : https://github.com/mybatis/mybatis-3

  • That is, data (such as objects in memory) is saved to a storage device (such as a disk) that can be saved permanently. The main application of persistence is to store objects in memory in a database, or in disk files, XML data files, etc.

  • Data will be lost when the memory is powered off, but there are some objects that cannot be lost in any case, such as bank account numbers. Unfortunately, people cannot guarantee that the memory will never lose power.

  • Memory is too expensive. Compared with external storage such as hard drives and optical disks, the price of memory is 2 to 3 orders of magnitude higher, and the maintenance cost is also high. At least it needs to be powered all the time. Therefore, even if the object does not need to be saved permanently, it cannot stay in the memory because of the memory capacity limit, and needs to be persisted to be cached in external memory.

  • The code block that completes the persistence work. ----> dao layer [DAO (Data Access Object) Data Access Object]

  • In most cases, especially in enterprise-level applications, data persistence often means saving the data in the memory to the disk for solidification, and the persistence process is mostly completed through various relational databases .

  • However, there is one word that needs special emphasis here, which is the so-called "layer". For application systems, data persistence functions are mostly essential components. In other words, our system already has the concept of "persistence layer" naturally? Maybe, but maybe that's not the case. The reason why we need to create a separate concept of "persistence layer" instead of "persistence module" or "persistence unit" means that there should be a relatively independent logical layer in our system architecture that focuses on data persistence. Logical implementation.

  • Compared with other parts of the system, this level should have a clearer and stricter logical boundary. [To put it bluntly, it is used to operate the database!

  • Mybatis helps programmers store data into the database and retrieve data from the database.

  • Traditional jdbc operations have many repeated code blocks. For example: encapsulation when retrieving data, establishing connection to the database, etc..., the framework can reduce repeated code and improve development efficiency.

  • MyBatis is a semi-automated ORM framework (Object Relationship Mapping) --> Object Relationship Mapping

  • All things can still be done without Mybatis, but with it, all implementations will be simpler! There is no distinction between high and low technology, only the people who use this technology are different.

  • Advantages of MyBatis

    • Easy to learn: itself is small and simple. There are no third-party dependencies. The simplest installation only requires two jar files + configuring several sql mapping files. It is easy to learn and use. Through the documentation and source code, you can fully grasp its design ideas and implementation.

    • Flexible: mybatis does not impose any impact on the existing design of the application or database. SQL is written in xml, which facilitates unified management and optimization. All needs for operating the database can be met through sql statements.

    • Decouple SQL from 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 xml tags to support writing dynamic sql.

    • .......

  • The most important thing is that more people use it! The company needs it!

  • JDBC is a persistence mechanism. File IO is also a persistence mechanism.

  • In life: The same method is used to refrigerate fresh meat and defrost it when eating. The same goes for canning fruit.

Guess you like

Origin blog.csdn.net/weixin_46996561/article/details/125265974