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.

  • 相关阅读:
    SaltStack概述及安装
    Zabbix高可用
    Zabbix数据库表结构
    asp select count(*) 用 open还是excute
    asp+jquery+ajax,asp后台程序执行不正常
    aspupload ,在winows server 2008 下无法使用
    jquery 如何使用innerHTML
    thinkphp的select和find的区别(转)
    centos安装PHP-pdo支持pdo
    Excel 2007 打开 UTF-8 编码 CSV 文件的乱码BUG
  • 原文地址:https://www.cnblogs.com/huey/p/5227523.html
Copyright © 2011-2022 走看看