MyBatis配置文件模板

Mybatis-config.xml

Mybatis-config.xml一般为Mybatis的主配置文件, 一个工程只能有一个

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?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="db.properties"/>

<!-- 设置mybatis自带的一些功能 -->
<settings>
<!-- 具体设置, 这里的是开启驼峰命名法与下划线之间转换 -->
<setting name="mapUnderscoreToCamelCase" value="true"/>
</settings>

<!-- 配置别名 -->
<typeAliases>
<!-- 指定的包名 -->
<package name=""/>
</typeAliases>

<!-- 配置插件 -->
<plugins>
<!-- 具体插件 -->
<!-- 这里的是一个分页插件拦截器 -->
<plugin interceptor="com.github.pagehelper.PageInterceptor">
<property name="reasonable" value="true"/>
</plugin>
</plugins>

<!-- 配置默认连接环境 -->
<environments default="mysql_developer">
<!-- 连接环境具体信息 -->
<environment id="mysql_developer">
<!-- 使用jdbc事务管理方式 -->
<transactionManager type="jdbc"/>
<!-- 连接池 -->
<dataSource type="pooled">
<!-- 取出属性文件中的四个必要属性 -->
<property name="driver" value="${mysql.driver}"/>
<property name="url" value="${mysql.url}"/>
<property name="username" value="${mysql.username}"/>
<property name="password" value="${mysql.password}"/>
</dataSource>
</environment>
</environments>


</configuration>

将这个模板保存到IDE的模板配置里面就可以了

Author: klenq
Link: https://klenq.github.io/2021/11/15/MyBatis配置文件模板/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.