1、引入依赖
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.6</version>
</dependency>
2、配置文件模板
<?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>
<!--配置内容。。。。。。-->
</configuration>
3、以mysql为数据源举例
<?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>
<!--设置sql日志 打印在控制台-->
<settings>
<setting name="logImpl" value="STDOUT_LOGGING"/>
</settings>
<!--配置别名-->
<typeAliases>
<!--此包下的实体类名===别名-->
<package name="com.ydx.entity"/>
</typeAliases>
<!--分页插件-->
<!--插件-->
<plugins>
<plugin interceptor="com.github.pagehelper.PageInterceptor"/>
</plugins>
<!--数据源 -->
<environments default="mydb">
<environment id="mydb">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<!--载入驱动等信息-->
<property name="driver" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/db3"/>
<property name="username" value="root"/>
<property name="password" value="123456"/>
</dataSource>
</environment>
</environments>
<!--管理映射源文件-->
<mappers>
<mapper resource="DaoMapper/UserDaoMapper.xml"/>
</mappers>
</configuration>