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.

  • 相关阅读:
    深度学习大牛Yoshua Bengio
    mysql select简单用法
    CF 191 div2
    MySQL 讨厌哪种类型的查询
    Python 中的list小结
    定时器常用的两种工作方式及编程要点
    Linux下which、whereis、locate、find 区别
    Dalvik虚拟机的优化机制
    [leetcode]Partition List
    tomcat:Could not publish to the server. java.lang.IndexOutOfBoundsException
  • 原文地址:https://www.cnblogs.com/huey/p/5227523.html
Copyright © 2011-2022 走看看