Mybaties-引入外部配置文件和别名
作者:互联网
mybatis-config.xml
<?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>
<!--引入外部配置文件-->
<properties resource="db.properties" />
<!--可以给实体类起别名-->
<typeAliases>
<typeAlias type="com.kuang.pojo.User" alias="User"/>
</typeAliases>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="${driver}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
</dataSource>
</environment>
</environments>
<!--每一个Mapper.xml都需要在Mybatis核心配置文件中注册!-->
<mappers>
<mapper resource="com/kuang/dao/UserMapper.xml"/>
<!-- <mapper class="com.kuang.dao.UserMapper"/> -->
<!-- <package name="com.kuang.dao"/> -->
</mappers>
</configuration>
db.properties 注意:外部文件优先级高于核心文件的设置
driver = com.mysql.cj.jdbc.Driver
url = jdbc:mysql://localhost:3306/mybatis?useSSL=true&usUnicode=true&characterEncoding=UTF-8&autoReconnect=true&failOverReadOnly=false&serverTimezone=UTC
username = root
password = lgz0921
lgz0921 发布了195 篇原创文章 · 获赞 27 · 访问量 2万+ 私信 关注
标签:Mybaties,jdbc,配置文件,外部,lgz0921,别名,mysql,mybatis,true 来源: https://blog.csdn.net/lgz0921/article/details/104099137