mybatis相关依赖包
<dependencies>
<!--mybatis的依赖包-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.9</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.31</version>
</dependency>
<!--junit单元测试的依赖-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<!--范围:只在test下有效-->
<scope>test</scope>
</dependency>
</dependencies>
mybatis核心配置文件
<?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" />
<dataSource type="POOLED">
<property name="driver" value="com.mysql.cj.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/mybatis" />
<property name="username" value="root" />
<property name="password" value="root" />
</dataSource>
</environment>
</environments>
</configuration>
mybatis其他辅助功能
<?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>
<!--引入数据库配置文件-->
<properties resource="jdbc.properties">
</properties>
<!--自动驼峰命名映射-->
<settings>
<setting name="mapUnderscoreToCamelCase" value="true"/>
</settings>
<!--起别名-->
<typeAliases>
<!--<typeAlias type="pojo.User" alias="User"/>-->
<package name="pojo"/>
</typeAliases>
<!-- 分页助手的插件 -->
<plugins>
<plugin interceptor="com.github.pagehelper.PageHelper">
<!--dialect: 指定方言 limit-->
<property name="dialect" value="mysql"/>
</plugin>
</plugins>
<!--环境配置-->
<environments default="development">
<!--使用MySQL环境-->
<environment id="development">
<!--使用JDBC类型事务管理器-->
<transactionManager type="JDBC"></transactionManager>
<!--使用连接池-->
<dataSource type="POOLED">
<property name="driver" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql:///mybatis2?useUnicode=true&characterEncoding=utf-8"></property>
<property name="username" value="root"></property>
<property name="password" value="123456"></property>
</dataSource>
</environment>
</environments>
<!--加载映射配置-->
<mappers>
<package name="mapper"/>
</mappers>
</configuration>
mybatis日志工厂,如果想要打印日志,则需要将日志工厂配置到mybatis配置文件中,注意标签顺序
<settings>
<setting name="mapUnderscoreToCamelCase" value="true"/>
</settings>
分页助手pom文件,如果想要使用分页助手插件,则需要配置一下pom文件
<!-- 分页助手 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>3.7.5</version>
</dependency>
<dependency>
<groupId>com.github.jsqlparser</groupId>
<artifactId>jsqlparser</artifactId>
<version>0.9.1</version>
</dependency>