What MyBatis-Plus
Plus-MyBatis (abbreviated MP) is a MyBatis enhancement tools, enhanced not only change on the basis of MyBatis, to simplify development tedious CRUD, improved code efficiency and health, while providing a code generator and pagination plug-in, support Spring boot, spring mvc development.
what is the benefit
Property
- Non-invasive : not only enhance the change, it will not have an impact on the introduction of existing projects, such as silky smooth
- Loss is small : the basic injection start automatically CURD i.e., substantially no loss of performance, object-oriented operating direct
- Powerful CRUD operations : built-in universal Mapper, Universal Service, the configuration can be achieved only by a small amount of single-table most of the CRUD operations, more powerful conditions constructors, to meet the various needs
- Lambda forms of support calls : The Lambda expressions, easy preparation of various types of query conditions, without having to worry about the wrong field
- Automatic generation of primary key support : supports up to four primary key strategies (Distributed contains a unique ID generator - Sequence), freely configurable, perfect to solve the primary key issue
- Support ActiveRecord model : ActiveRecord form of support calls, just like an entity class inherits Model can be a powerful CRUD operations
- Support custom global General Procedure : general procedure supports global injection (Write once, use anywhere)
- Built-in code generator : the use of code or Maven plugin can quickly generate Mapper, Model, Service, Controller layer code, support template engine, more and more super custom configuration waiting for you to use
- Built-in pagination plug-in : after MyBatis based on physical pages, developers need not concern specific operations, configure the plug-in, written paging equivalent to general inquiries List
- Pagination plug-in supports multiple databases : support for MySQL, MariaDB, Oracle, DB2, H2, HSQL, SQLite, Postgre, SQLServer and other databases
- Built-in performance analysis plug-ins : Sql statement can be output as well as its execution time, this feature is enabled recommends that developers test time, can quickly ferret out slow query
- Built-in global blocking plug-ins : Provide a full table delete, update operational intelligence analysis block, also can customize the blocking rules to prevent misuse
Support Database
- mysql 、 mariadb 、 oracle 、 db2 、 h2 、 hsql 、 sqlite 、 postgresql 、 sqlserver
- Dream up a database, Xu Gu database, the NPC gold warehouse database
Framework
Integration with a spring boot
Add pom.xml dependence
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version>
<relativePath/>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.0</version>
</dependency>
<!-- 提供mysql驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
Configuration application.yml
server:
port: 80
spring:
application:
name: mp
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.driver
url: jdbc:mysql://localhost:3306/mp?autoReconnect=true&useSSL=false&allowPublicKeyRetrieval=true
username: root
password: 1234
mybatis-plus:
mapper-locations:classpath: mapper/*Mapper.xml
type-aliases-package: com.mp.entity
Create a startup class MpApplication.java
@EnableTransactionManagement
@SpringBootApplication
@MapperScan("com.yiyang.mapper")
public class MpApplication {
public static void main(String[] args) {
SpringApplication.run(MpApplication.class, args);
}
}
Creating the Entity Classes
@Data
@TableName("user")
public class User {
@TableId(type=IdType.INPUT)
private Long id;
@TableField
private String name;
@TableField
private Integer age;
@TableField
private String email;
/**...setter,getter......*/
}
Run on the Ok