MyBatis(3.2.3) - Configuring MyBatis using XML, Properties
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.
MyBatis(3.2.3) - Configuring MyBatis using XML, Properties的更多相关文章
- MyBatis(3.2.3) - Configuring MyBatis using XML, Environment
The key component of MyBatis is SqlSessionFactory from which we get SqlSession and execute the mappe ...
- MyBatis(3.2.3) - Configuring MyBatis using XML, typeHandlers
As discussed in the previous chapter, MyBatis simplifies the persistent logic implementation by abst ...
- MyBatis(3.2.3) - Configuring MyBatis using XML, typeAliases
In the SQL Mapper configuration file, we need to give the fully qualified name of the JavaBeans for ...
- MyBatis(3.2.3) - Configuring MyBatis using XML, Settings
The default MyBatis global settings, which can be overridden to better suit application-specific nee ...
- MyBatis(3.2.3) - Configuring MyBatis using XML, Mappers
Mapper XML files contain the mapped SQL statements that will be executed by the application using st ...
- Mybatis增加对象属性不增加mapper.xml的情况
Mybatis增加对象属性不增加mapper.xml的情况: 只增加Model 对象的属性,在查询语句中返回相同名称的字段,但是在mapper中的 resultMap上面不进行新增字段的增加,查询结果 ...
- Mybatis学习总结(三)——SqlMapConfig.xml全局配置文件解析
经过上两篇博文的总结,对mybatis中的dao开发方法和流程基本掌握了,这一节主要来总结一下mybatis中的全局配置文件SqlMapConfig.xml在开发中的一些常用配置,首先看一下该全局配置 ...
- Java Persistence with MyBatis 3(中文版) 第三章 使用XML配置SQL映射器
关系型数据库和SQL是经受时间考验和验证的数据存储机制.和其他的ORM 框架如Hibernate不同,MyBatis鼓励开发者可以直接使用数据库,而不是将其对开发者隐藏,因为这样可以充分发挥数据库服务 ...
- Mybatis手工写sql语句及Mapper.xml方法
首先在项目中 建一个mapper包,然后在spring集合mybatis的配置文件中设置扫描这个mapper包 然后,建 封装查询结果需要的 pojo 然后,在 mapper包中创建 Mapper接口 ...
随机推荐
- substr函数
substr(字符串,截取开始位置,截取长度) //返回截取的字 substr('Hello World',0,1) //返回结果为 'H' *从字符串第一个字符开始截取长度为1的字符串 subst ...
- SAE搭建WordPress教程 免费建WordPress博客站
SAE搭建WordPress教程 免费建WordPress博客站 WordPress是一种使用PHP语言开发的博客平台,用户可以在支持PHP和MySQL数据库的服务器上架设自己的网志.当然,用户也可以 ...
- [1.1]Knowledge that should be prepared
Actually, there are a huge amount of knowledge we need to learn. So I hope you don't be scared. It's ...
- sql 指令
SELECT 是用来做什么的呢?一个最经常使用的方式是将资料从数据库中的表格内选出.从这一句回答中.我们立即能够看到两个keyword:从 (FROM)数据库中的表格内选出 (SELECT).(表格是 ...
- Middleware课程01-概述
中间件是一种独立的系统软件或服务程序,分布式应用软件借助这种软件在不同的技术之间共享资源.中间件位于客户机/ 服务器的操作系统之上,管理计算机资源和网络通讯.是连接两个独立应用程序或独立系统的软件.相 ...
- URAL 1774 A - Barber of the Army of Mages 最大流
A - Barber of the Army of MagesTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/v ...
- 解决easyui-datagrid在ie中无法reload问题
easyui在页面载入时,会自己主动填充datagrid中的数据,当加入.改动.删除后,会触发reload事件,对datagrid进行又一次载入. 这个过程在FireFox中没有问题,用firebug ...
- xtrabackup原理2
XTRABACKUP备份原理实现细节——对淘宝数据库内核月报补充 前言 淘宝3月的数据库内核月报对xtrabackup的备份原理做了深入的分析,写的还是很不错.不过Inside君在看完之后,感觉没有对 ...
- mysql 支持emoji
1.修改my.cnf [client] default-character-set = utf8mb4 [mysqld] collation-server = utf8mb4_unicode_ci c ...
- oracle 基本操作
1. 开启oralce和监听#su - oracle$sqlplus / as sysdba>startup>exit$lsnrctl start$ps -ef|grep oracle 一 ...