总的文件结构:
1、先创建mybatis数据库,在该数据库下执行该语句:
create table employee(
id int primary key auto_increment,
name varchar(20) not null ,
age int not null,
position varchar(20)
);
insert into employee(id, name, age, position) VALUES
(null,'张三',20,'员工'),
(null,'李四',18,'员工'),
(null,'王五',35,'经理');
2.创建idea Maven工程
在resources目录下分别创建db.properties和mybatis-config.xml文件,内容分别为:
db.properties:
mysql.driver=com.mysql.cj.jdbc.Driver
mysql.username=root
mysql.password=123456
mysql.url=jdbc:mysql://localhost:3306/mybatis
mybatis-config.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"" target="_blank">http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<properties resource="db.properties"></properties>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"></transactionManager>
<dataSource type="POOLED">
<property name="driver" value="${mysql.driver}"/>
<property name="url" value="${mysql.url}"/>