目录
1. 准备工作
数据库准备:
创建Maven 父模块
2. Mybatis 整合 Mybatis-Plus
创建子模块:
准备 log4j.properties 日志文件
3. Mybatis 原生写法实现查询User
编写mybatis-config.xml文件:
编写User实体对象:(这里使用lombok进行了进化bean操作)
编写UserMapper接口
编写UserMapper.xml文件:
编写TestMybatis测试用例:
4. Mybatis + Mybatis-Plus整合查询User
将UserMapper继承BaseMapper,将拥有了BaseMapper中的所有方法:
使用MP中的MybatisSqlSessionFactoryBuilder进行构建:
运行报错:
解决: 在User对象中添加 @TableName, 指定该类映射的数据库表名. (默认是数据库.实体类类名小写)
测试结果:
简要说明:
5. Spring + Mybatis + Mybatis-Plus整合
创建子Module
编写jdbc.properties
编写log4j.properties
编写applicationContext.xml
编写User对象以及UserMapper接口:
编写测试用例:
测试结果:
6.SpringBoot + Mybatis + Mybatis-Plus整合查询User
创建SpringBoot项目导入相关依赖
log4j.properties:
编写application.properties
编写pojo 和 mapper
编写启动类
编写测试用例
测试结果
对于Mybatis整合MybatisPlus常常有三种用法,分别是 Mybatis + Mybatis-Plus 、Spring + Mybatis + Mybatis-Plus、SpringBoot + Mybatis + Mybatis-Plus
1. 准备工作
数据库准备:
-- 创建数据库
create database mybatis_plus_practice;
-- 使用数据库
USE mybatis_plus_practice;
-- 创建测试表
CREATE TABLE `tb_user` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`user_name` varchar(20) NOT NULL COMMENT '用户名',
`password` varchar(20) NOT NULL COMMENT '密码',
`name` varchar(30) DEFAULT NULL COMMENT '姓名',
`age` int(11) DEFAULT NULL COMMENT '年龄',
`email` varchar(50) DEFAULT NULL COMMENT '邮箱',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
-- 插入测试数据
INSERT INTO `tb_user` (`id`, `user_name`, `password`, `name`, `age`, `email`)
VALUES('1', 'zhangsan', '123456', '张三', '18', 'test1@163.cn');
INSERT INTO `tb_user` (`id`, `user_name`, `password`, `name`, `age`, `email`) VALUES('2', 'lisi', '123456', '李四', '20', 'test2@163.cn');
INSERT INTO `tb_user` (`id`, `user_name`, `password`, `name`, `age`, `email`) VALUES('3', 'wangwu', '123456', '王五', '28', 'test3@163.cn');
INSERT INTO `tb_user` (`id`, `user_name`, `password`, `name`, `age`, `email`) VALUES('4', 'zhaoliu', '123456', '赵六', '21', 'test4@163.cn');
INSERT INTO `tb_user` (`id`, `user_name`, `password`, `name`, `age`, `email`) VALUES('5', 'sunqi', '123456', '孙七', '24', 'test5@163.cn');
创建Maven 父模块
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>indi.darylz</groupId>
<artifactId>mybatis-plus-simple</artifactId>
<version>1.0-SNAPSHOT</version>
<modules>
<module>mybatis-plus-mybatis</module>
</modules>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<packaging>pom</packaging>
<!-- 导入相关依赖-->
<dependencies>
<!-- mybatis-plus插件依赖 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
<version>3.1.1</version>
</dependency>
<!-- MySql 连接驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.16</version>
</dependency>
<!-- 连接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.11</version>
</dependency>
<dependency>
<!-- 简化bean代码的工具包 -->
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
<version>1.18.4</version>
</dependency>
<!-- 单元测试-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<!-- 日志工具包-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
2. Mybatis 整合 Mybatis-Plus
创建子模块:
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>indi.darylz</groupId>
<artifactId>mybatis-plus-simple</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<packaging>jar</packaging>
<artifactId>mybatis-plus-mybatis</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
准备 log4j.properties 日志文件
log4j.rootLogger=DEBUG,A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=[%t] [%c]-[%p] %m%n
3. Mybatis 原生写法实现查询User
编写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>
<settings>
<!-- 开启驼峰,开启后,只要数据库字段和对象属性名字母相同,
无论中间加多少下划线都可以识别 -->
<setting name="mapUnderscoreToCamelCase" value="true"/>
</settings>
<environments default="development">
<!-- 配置数据源 -->
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<!-- 由于使用的mysql8的版本, 驱动类是 com.mysql.cj.jdbc.Driver
mysql5驱动版本是 com.mysql.jdbc.Driver-->
<property name="driver" value="com.mysql.cj.jdbc.Driver"/>
<!-- 由于使用的mysql8的版本, url中一定要加入时区! 否则报时区错误异常
#北京东八区 serverTimezone=GMT%2B8
#上海时区 serverTimezone=Asia/Shanghai-->
<property name="url" value="jdbc:mysql://127.0.0.1:3306/mybatis_plus_practice?serverTimezone=GMT%2B8&
characterEncoding=utf8&useUnicode=true&useSSL=true"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
</dataSource>
</environment>
</environments>
<mappers>
<!-- 通过resource属性引入classpath路径的相对资源-->
<mapper resource="UserMapper.xml"/>
</mappers>
</configuration>
编写User实体对象:(这里使用lombok进行了进化bean操作)
package indi.darylz.pojo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author daryl z
* @description description_write_here
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class User {
private Long id;
private String userName;
private String password;
private String name;
private Integer age;
private String email;
}
编写UserMapper接口
package indi.darylz.mapper;
import indi.darylz.pojo.User;
import java.util.List;
/**
* @author: daryl z
* @description: description_write_here
*/
public interface UserMapper {
List<User> findAll();
}
编写UserMapper.xml文件:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="indi.darylz.mapper.UserMapper">
<select id="findAll" resultType="indi.darylz.pojo.User">
SELECT * FROM tb_user;
</select>
</mapper>
编写TestMybatis测试用例:
package indi.darylz;
import indi.darylz.mapper.UserMapper;
import indi.darylz.pojo.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Before;
import org.junit.Test;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
/**
* @author: daryl z
* @description: description_write_here
*/
public class TestMybatis {
private UserMapper userMapper;
@Before
public void getUserMapperInstance() throws IOException {
String resource = "mybatis-config.xml";
// 读取当前类路径下的配置文件获取一个 输出流
InputStream inputStream = Resources.getResourceAsStream(resource);
// 然后 再通过 Mybatis 的 会话工厂建造器,获取一个会话工厂
SqlSessionFactory sessionFactory =
new SqlSessionFactoryBuilder().build(inputStream);
// 打开会话获取一个 会话实例
SqlSession sqlSession = sessionFactory.openSession();
// 通过 会话实例 get 一个 UserMapper 的 代理对象
userMapper = sqlSession.getMapper(UserMapper.class);
}
@Test
public void testFindAll() {
List<User> userList = userMapper.findAll();
for (User user : userList) {
System.out.println(user);
}
}
}
测试结果:
4. Mybatis + Mybatis-Plus整合查询User
将UserMapper继承BaseMapper,将拥有了BaseMapper中的所有方法:
package indi.darylz.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import indi.darylz.pojo.User;
import java.util.List;
/**
* @author: daryl z
* @description: description_write_here
*/
public interface UserMapper extends BaseMapper<User> {
List<User> findAll();
}
使用MP中的MybatisSqlSessionFactoryBuilder进行构建:
package indi.darylz;
import com.baomidou.mybatisplus.core.MybatisSqlSessionFactoryBuilder;
import indi.darylz.mapper.UserMapper;
import indi.darylz.pojo.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.junit.Before;
import org.junit.Test;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
/**
* @author: daryl z
* @description: description_write_here
*/
public class TestMybatisMybatisPlus{
private UserMapper userMapper;
@Before
public void getUserMapperInstance() throws IOException {
String resource = "mybatis-config.xml";
// 读取当前类路径下的配置文件获取一个 输出流
InputStream inputStream = Resources.getResourceAsStream(resource);
//这里使用的是Mybatis-Plus 中的MybatisSqlSessionFactoryBuilder 进行构建
SqlSessionFactory sessionFactory =
new MybatisSqlSessionFactoryBuilder().build(inputStream);
// 打开会话获取一个 会话实例
SqlSession sqlSession = sessionFactory.openSession();
// 通过 会话实例 get 一个 UserMapper 的 代理对象
userMapper = sqlSession.getMapper(UserMapper.class);
}
@Test
public void testSelectList() {
List<User> userList = userMapper.selectList(null);
for (User user : userList) {
System.out.println(user);
}
}
}
运行报错:
解决: 在User对象中添加 @TableName, 指定该类映射的数据库表名. (默认是数据库.实体类类名小写)
package indi.darylz.pojo;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author daryl z
* @description description_write_here
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@TableName("tb_user")
public class User {
private Long id;
private String userName;
private String password;
private String name;
private Integer age;
private String email;
}
测试结果:
简要说明:
由于使用 MybatisSqlSessionFactoryBuilder(这个类是 Mybatis官方的 SqlSessionFactoryBuilder 类的子类 )进行了构建,继承的BaseMapper中的方法就载入到了SqlSession中, 所以就可以直接使用相关的方法;
5. Spring + Mybatis + Mybatis-Plus整合
引入了Spring框架,数据源、构建等工作就交给了Spring管理。
创建子Module
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>indi.darylz</groupId>
<artifactId>mybatis-plus-simple</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>mybatis-plus-spring</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.version>5.1.8.RELEASE</spring.version>
</properties>
<dependencies>
<!-- 导入Spring相关依赖-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
</project>
编写jdbc.properties
jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://127.0.0.1:3306/mybatis_plus_practice?serverTimezone=GMT%2B8&characterEncoding=utf8&useUnicode=true&useSSL=true
jdbc.username=root
jdbc.password=root
编写log4j.properties
log4j.rootLogger=DEBUG,A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=[%t] [%c]-[%p] %m%n
编写applicationContext.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd">
<!-- 启动Spring项目时扫描到 数据库连接的配置文件 -->
<context:property-placeholder location="classpath:*.properties"/>
<!-- 配置数据源 -->
<bean class="com.alibaba.druid.pool.DruidDataSource" id="dataSource" destroy-method="close">
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<property name="driverClassName" value="${jdbc.driver}"/>
<!-- maxActive: 最主要参数,配置连接池同时能维持的最大连接数,如果客户端理论上需要100个连接,则这个值设为100。 -->
<property name="maxActive" value="10"/>
<!--minIdle:连接池中的最小空闲连接数,Druid会定时扫描连接池的连接,
如果空闲的连接数大于该值,则关闭多余的连接,
反之则创建更多的连接以满足最小连接数要求。-->
<property name="minIdle" value="5"/>
</bean>
<!-- 这里使用 Mybatis-Plus提供的 sqlSessionFactory,完成 Spring与Mybatis-Plus的整合 -->
<bean class="com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean"
id="mybatisSqlSessionFactoryBean">
<!-- 将druid连接池注入到 MybatisSqlSessionFactoryBean 的 dataSource属性 中 -->
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 扫描mapper 接口, 使用的依然是 Mybatis原生的扫描器 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 将包名注入到 MapperScannerConfigurer 的 basePackage 中 -->
<property name="basePackage" value="indi.darylz.mapper"/>
</bean>
</beans>
编写User对象以及UserMapper接口:
package indi.darylz.pojo;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author daryl z
* @description description_write_here
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@TableName("tb_user")
public class User {
private Long id;
private String userName;
private String password;
private String name;
private Integer age;
private String email;
}
package indi.darylz.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import indi.darylz.pojo.User;
/**
* @author: daryl z
* @description: description_write_here
*/
public interface UserMapper extends BaseMapper<User> {
}
编写测试用例:
package indi.darylz.test;
import indi.darylz.mapper.UserMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author: daryl z
* @description: description_write_here
*/
// 注入 Spring整合Junit的 运行器
@RunWith(SpringJUnit4ClassRunner.class)
// 指定上下文配置, 读取哪个文件的配置?
@ContextConfiguration(locations = "classpath:application-context.xml")
public class TestSpringMybatisPlus {
/* 注入UserMapper的代理对象 */
@Autowired
private UserMapper userMapper;
@Test
public void testSelectList(){
userMapper.selectList(null).forEach(System.out::println);
}
}
测试结果:
6.SpringBoot + Mybatis + Mybatis-Plus整合查询User
使用SpringBoot将进一步的简化 Mybatis-Plus的整个, 需要注意的是,由于使用SpringBoot 需要继承 parent, 所以需要重新创建工程, 而不是去创建一个 子Module
创建SpringBoot项目导入相关依赖
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<!-- SpringBoot 父模块 GAV -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.5.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>indi.darylz</groupId>
<artifactId>mybatis-plus-springboot</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- 导入 SpringBoot相关依赖-->
<!-- SpringBoot启动器 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</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>
<!--mybatis-plus启动器的 springboot支持-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.0</version>
</dependency>
<!--mysql驱动-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.16</version>
</dependency>
<!-- 日志工具包 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
</dependencies>
<!-- 打包插件 -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
log4j.properties:
log4j.rootLogger=debug,A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=[%t] [%c]-[%p] %m%n
# 关闭 springboot2 的自动装配日志报告 CONDITIONS EVALUATION REPORT
# 的 debug 级别, 更改为 error级别, 不然有的日志看不见,
# 比如有时 Mybatis-Plus生成SQL语句的日志
log4j.logger.org.springframework.boot.autoconfigure=ERROR
编写application.properties
spring.application.name=darylz-mybatis-plus-springboot
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/mybatis_plus_practice?serverTimezone=GMT%2B8&characterEncoding=utf8&useUnicode=true&useSSL=true
spring.datasource.username=root
spring.datasource.password=root
编写pojo 和 mapper
package indi.darylz.pojo;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author daryl z
* @description description_write_here
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@TableName("tb_user")
public class User {
private Long id;
private String userName;
private String password;
private String name;
private Integer age;
private String email;
}
package indi.darylz.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import indi.darylz.pojo.User;
/**
* @author: daryl z
* @description: description_write_here
*/
public interface UserMapper extends BaseMapper<User> {
}
编写启动类
package indi.darylz;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @author: daryl z
* @description: description_write_here
*/
@MapperScan("indi.darylz.mapper") // 设置 mapper 接口的扫描基包
@SpringBootApplication
public class SpringBootMybatisPlusApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootMybatisPlusApplication.class, args);
}
}
编写测试用例
package indi.darylz;
import indi.darylz.mapper.UserMapper;
import indi.darylz.pojo.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.List;
/**
* @author: daryl z
* @description: description_write_here
*/
@RunWith(SpringRunner.class)
@SpringBootTest
public class TestMybatisPlusSpringBoot {
@Autowired
private UserMapper userMapper;
@Test
public void testSelectList() {
List<User> users = userMapper.selectList(null);
for (User user : users) {
System.out.println(user);
}
}
}