MyBatis-plus 实战学习
#1.简单建一个springboot工程
#2.引入maven配置
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.2.0</version>
</dependency>
#3.建几张简单的表
员工表
CREATE TABLE `t_emp` (
`id` int(11) NOT NULL,
`age` int(11) NULL DEFAULT NULL,
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
)
部门表
CREATE TABLE `t_depart` (
`id` int(11) NOT NULL,
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`parent_id` int(11) NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
)
员工和部门的关联表
CREATE TABLE `t_emp_depart` (
`id` int(11) NOT NULL,
`emp_id` int(11) NULL DEFAULT NULL,
`depart_id` int(11) NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
)
#4.配置数据库连接,mybatis配置
#数据库配置
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/mybatis_demo?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=1234
#mybatis配置
mybatis-plus.mapper-locations=classpath:mapper/*.xml
mybatis-plus.global-config.db-config.id-type=auto