mybatis_14_配置中的属性动态替换

参考mybatis的dtd文件:http://mybatis.org/dtd/mybatis-3-config.dtd,存在properties标签,此标签可以在外部进行属性配置,动态替换dataSource内的属性值

代码示例:

properties.property中name为url的值将替换dataSource.property中name为url的值

<?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>
        <property name="url" value="jdbc:postgresql://172.16.x.x:5432/database_name"/>
    </properties>
    <environments default="development">
        <environment id="development">
            <transactionManager type="JDBC"/>
            <dataSource type="POOLED">
                <property name="driver" value="org.postgresql.Driver"/>
                <property name="url" value="${url}"/>
                <property name="username" value="xxx"/>
                <property name="password" value="xxx"/>
            </dataSource>
        </environment>
    </environments>
    <mappers>
        <mapper resource="tk/mybatis/simple/mapper/IndicatorMapper.xml"/>
    </mappers>
</configuration>

  

posted @ 2022-10-18 14:46  留白*  阅读(81)  评论(0编辑  收藏  举报