MyBatis-Plus是Mybatis的增强工具,在Mybaits的基础上只作增强不做改变,为简化开发,提高效率而生。
官网:https://baomidou.com/
<dependency>
<groupId>com.baomidougroupId>
<artifactId>mybatis-plusartifactId>
<version>3.5.2version>
dependency>
特性:
架构
MyBatis整合MP有三种方法:
MyBatis查询User:
1.编写mybatis-config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<!--核心配置文件-->
<configuration>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"></transactionManager>
<dataSource type="POOLED">
<property name="driver" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/mp?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="UserMapper.xml"/>
</mappers>
</configuration>
2.编写User实体类
package cn.itcast.mp.simple.pojo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class User {
// 使用了lombok的注解 生成set和get方法
private Long id;
private String user_name;
private String password;
private String name;
private Integer age;
private String email;
}
3.编写UserMapper接口
package cn.itcast.mp.simple.mapper;
import cn.itcast.mp.simple.pojo.User;
import java.util.List;
public interface Usermapper {
public List