1

【笔记】MyBatis多个数据库配置

 1 year ago
source link: https://feiju12138.github.io/2022/09/25/MyBatis%E5%A4%9A%E4%B8%AA%E6%95%B0%E6%8D%AE%E5%BA%93%E9%85%8D%E7%BD%AE/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

在项目中可以同时配置开发环境的数据库和生产环境的数据库,实现来回切换

配置多个数据库

src/main/resources/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 >
<!-- 选择一个当前的默认配置 -->
<environments default="master">

<!-- 定义用于开发环境的数据库 -->
<environment id="develop">
...
</environment>

<!-- 定义用于生产环境的数据库 -->
<environment id="master">
...
</environment>
</environments>

</configuration>

哔哩哔哩——黑马程序员


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK