zoukankan      html  css  js  c++  java
  • MyBatis(3.2.3)

    The properties configuration element can be used to externalize the configuration values into a properties file and use the properties' key names as placeholders. In the preceding configuration, we have externalized the database connection properties into the application.properties file and used placeholders for the driver, URL, and so on.

    1. Configure the database connection parameters in application.properties as follows:

    jdbc.driverClassName=com.mysql.jdbc.Driver
    jdbc.url=jdbc:mysql://localhost:3306/mybatisdemo
    jdbc.username=root
    jdbc.password=admin

    2. In mybatis-config.xml, use the placeholders for the properties defined in application.properties.

    <properties resource="application.properties">
        <property name="jdbc.username" value="db_user"/>
        <property name="jdbc.password" value="verysecurepwd"/>
    </properties>
    
    <dataSource type="POOLED">
        <property name="driver" value="${jdbc.driverClassName}"/>
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
    </dataSource>

    Also, you can configure the default parameter values inside the <properties> element; they will be overridden by the values in the properties file if there are properties with the same key name.

    <properties resource="application.properties">
        <property name="jdbc.username" value="db_user"/>
        <property name="jdbc.password" value="verysecurepwd"/>
    </properties>

    Here, the username and password values db_user and verysecurepwd will be overridden by the values in application.properties if the application. peroperties file contains the key names jdbc.username and jdbc.password.

  • 相关阅读:
    【转】【python】装饰器的原理
    Common Subsequence---最长公共子序列
    N个数的全排列 -------指定排头法
    Oil Deposits----深搜问题
    Worm
    亲和串
    n个数的最小公倍数
    整除的尾数
    Substrings 子字符串-----搜索
    N的互质数----欧拉函数
  • 原文地址:https://www.cnblogs.com/huey/p/5227523.html
Copyright © 2011-2022 走看看