mybatis-config.xml
YesMyBatis
The main configuration file is used to configure MvBatis data source and attribute information
Note: Tags must be written in order, otherwise an error will be reported
1.properties tag
- Define key-value pairs
<properties>
<property name="Test_url" value="jdbc:mysql://localhost:3306/school?useSSL=false"/>
</properties>
- Reference properties file Create new file
inresources
folderjdbc.properties
Test_driver=com.mysql.jdbc.Driver Test_url=jdbc:mysql://localhost:3306/school?useSSL=false Test_username=root Test_password=root
properties
resource
Referencejdbc.properties
files in tags<properties resource="jdbc.properties"></properties>
2.settings tag
Set MyBatis
job properties
<settings>
<!-- 启用二级缓存 -->
<setting name="cacheEnabled" value="true"/>
<!-- 启用懒加载 -->
<setting name="lazyLoadingEnabled" value="true"/>
<!-- ...... -->
</settings>
3.typeAliases tag
Give the entity class an alias. You can use the alias directly in the mapping file instead of the fully qualified name of the entity class.
<typeAliases>
<typeAlias type="com.swkj.pojo.Student" alias="Student"></typeAlias>
</typeAliases>
4.plugins tag
Configure myBatis plug-in
<plugins>
<plugin interceptor=""></plugin>
</plugins>
5.environments tag
environments
Configure database connection information in
<!-- 在environments中可以定义多个environment,每个environment可以定义一套连接配置 -->
<!-- default属性用来指定使用哪个environment -->
<environments default="Test">
<environment id="Test">
<!-- transactionManager用于配置数据库管理方式 -->
<!--
type 用于指定事务管理的方式
type="JDBC" 可以进行事务的提交和回滚操作
type="MANAGED" 依赖容器完成事务管理,本身不进行事务的提交和回滚操作
-->
<transactionManager type="JDBC"></transactionManager>
<!-- dataSource配置数据库连接信息 POOLED|UNPOOLED|JDNI -->
<dataSource type="POOLED">
<property name="driver" value="${Test_driver}"/>
<!-- characterEncoding=utf-8&-->
<property name="url" value="${Test_url}"/>
<property name="username" value="${Test_username}"/>
<property name="password" value="${Test_password}"/>
</dataSource>
</environment>
<environment id="oracle">
<transactionManager type=""></transactionManager>
<dataSource type=""></dataSource>
</environment>
</environments>
5.mappers tag
mappers 1. Used to load mapping files 2. Used to load DAO annotations
<mappers>
<mapper resource="mappers/StudentMapper.xml"></mapper>
</mappers>