Introduction to MyBatis-Plus

One: MyBatis advantages and disadvantages

Advantage:

  • SQL statements can be freely controlled, more flexible, and have higher performance.
  • SQL is separated from the code and is easy to read and maintain.
  • Provides XML tags to support writing dynamic SQL statements.

Disadvantage:

  • 单表There is no set of ready-made (CRUD) operations for simple 通用的增删改查operations, which requires us to write a set of them ourselves. Although each set of SQL is very simple, there are many such single-table operations in general systems. At this time, we will It needs to write a lot of sets, which is very cumbersome and a waste of time.

  • MyBatis itself is not rich enough, but supports Plugin, such as no built-in paging plug-in, no distributed ID support, etc.

The biggest shortcoming of MyBatis is that it does not provide a set of out-of-the-box general persistence operations for simple single-table operations. This is the biggest shortcoming. For MyBatis's own functions, it is not rich enough. In fact, this can be achieved in other ways.

2: Introduction to MyBatis-Plus

MyBatis-PlusAnd Mapper4is to solve the shortcomings of MyBatis single-table operation, which are commonly used in these two technology companies. Personally, I think Mapper4 is not as easy to use as MyBatis-Plus, and I feel that Mapper4 is not as elegant as MyBatis-Plus in use.

MyBatis-Plus ( https://mybatis.plus/ ) referred to as MP is an enhancement tool for MyBatis. It only enhances and does not change on the basis of MyBatis, and is born to simplify development and improve efficiency. MyBatis-Plus can quickly complete the operation of a single table without writing SQL statements . The vision of MyBatis-Plus is to become the best partner of MyBatis, just like the 1P and 2P in Contra. With basic friends, the efficiency is doubled.

insert image description here

  • GitHub(https://github.com/baomidou/mybatis-plus)

  • Code Cloud (https://gitee.com/organizations/baomidou/) MyBatis-Plus is developed by an 苞米豆organization called, the person in charge of the organization is called 青苗, there are about 31 people in the organization, they should all be Chinese.

  • MyBatis-Plus is very active in GitHub and commits are very frequent.

  • MyBatis-Plus is open sourced by the Chinese. The Chinese understand the needs of the Chinese best. The documents are in Chinese, and the comments are also in Chinese.

  • The first-line Internet company Tencent is using it, which shows that the reliability is trustworthy.

Three: MyBatis-Plus Features

  • Non-invasive: only make enhancements without changing, introducing it will not affect existing projects, smooth as silk
  • Low loss: Basic CURD is automatically injected at startup, performance is basically lossless, and direct object-oriented operation
  • Powerful CRUD operations: built-in general mapper and general service, most CRUD operations on a single table can be realized with only a small amount of configuration, and more powerful conditional constructors to meet various usage needs
  • Support Lambda form invocation: Through Lambda expressions, you can easily write various query conditions, and you don't need to worry about writing wrong fields.
  • Supports automatic primary key generation: supports up to 4 primary key strategies (including a distributed unique ID generator - Sequence), which can be freely configured to perfectly solve the primary key problem
  • Support ActiveRecord mode: Support ActiveRecord form call, entity class can perform powerful CRUD operations only by inheriting Model class
  • Support custom global general operations: support global general method injection ( Write once, use anywhere )
  • Built-in code generator: Use code or Maven plug-in to quickly generate Mapper , Model , Service , Controller layer code, support template engine, and more custom configurations waiting for you to use
  • Built-in paging plug-in: Based on MyBatis physical paging, developers do not need to care about specific operations. After configuring the plug-in, writing paging is equivalent to ordinary List query
  • The paging plugin supports multiple databases: MySQL, MariaDB, Oracle, DB2, H2, HSQL, SQLite, Postgre, SQLServer and other databases
  • Built-in performance analysis plug-in: It can output Sql statements and their execution time. It is recommended to enable this function during development and testing, which can quickly identify slow queries
  • Built-in global interception plug-in: provides intelligent analysis and blocking of delete and update operations on the entire table, and can also customize interception rules to prevent misoperation

  • Paging plugin: MyBatis uses pagehelper as a paging plugin.
  • Distributed ID: Many companies use Twitter's snowflake algorithm, IdWorker, as a distributed ID.
  • Autofill: It can be implemented by database default values ​​or by filling it yourself.
  • Code generator: MyBatis also provides a code generator. If you feel that the code generator provided by MyBatis is not good, you can write one yourself. It is actually very simple. We can get all the tables and all the corresponding data by connecting to the database. field, we can generate the file ourselves.
  • Enumeration value: This function is more practical.
  • Logical deletion: We can directly call the update method to modify the state.

Four: MyBatis-Plus Architecture

insert image description here

  1. Scan for entity classes.
  2. Analyze table and column names through reflection techniques.
  3. Generate Insert, Update, Delete, Select statements.
  4. Inject the generated CRUD statement into the MyBatis container.

Guess you like

Origin blog.csdn.net/weixin_45525272/article/details/123077950