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接口 ...
随机推荐
- 强连通分量(tarjan求强连通分量)
双DFS方法就是正dfs扫一遍,然后将边反向dfs扫一遍.<挑战程序设计>上有说明. 双dfs代码: #include <iostream> #include <cstd ...
- MVC神韵---你想在哪解脱!(十五)
在模型中添加验证规则 本节介绍如何在我们的Movie(电影)模型中添加一些验证规则,同时确认当用户使用我们的应用程序创建或编辑电影信息时将使用这些验证规则对用户输入的信息进行检查.首先,让我们在Mov ...
- 存储过程[st_MES_RptInspectShipment]
USE [ChangHong_612]GO/****** Object: StoredProcedure [dbo].[st_MES_RptInspectShipment] Script Date: ...
- UdpClient的Connect究竟做了什么(转)
最近在写一个音频通信的系统,因为需要还要处理其他事件,所以就自己设计底层的通信协议,用了不少底层的Socket编程(.Net Framework),搞清楚了不少细节问题. 先做一些铺垫工作.音频系统服 ...
- C# WebService的简单和复杂参数类型和结果的JSON格式
Jquery作为一款优秀的JS框架,简单易用的特性就不必说了.在实际的开发过程中,使用JQ的AJAX函数调用WebService 的接口实现AJAX的功能也成了一种比较普遍的技术手段了.WebServ ...
- spring中的ResourceBundleMessageSource
1 首先创建两个资源文件 messages_en_US.properties customer.name=Yong Mook Kim, age : {0}, URL : {1} messages ...
- C# 利用范型与扩展方法重构代码
在一些C#代码中常常可以看到 //An Simple Example By Ray Linn class CarCollection :ICollection { IList list; public ...
- delphi 01设置 字体属性
设置/获取 字体属性 名称 大小 粗体 斜体 下划线 删除线 颜色1 颜色2 uses MSHTML; //设置 //------------------------------------- ...
- oc-12-NSString 类简单介绍及用法
// 11-[掌握]NSString 类简单介绍及用法 #import <Foundation/Foundation.h> int main(int argc, const char * ...
- 项目源码--Android3D影音播放器源码
下载源码 技术要点: 1.本地音乐管理 2.音频流的解码 3. UI控件的综合使用 4. 视频流的解码 5. 动态更换皮肤 6. 3D效果的实现 7. 源码带详细的中文注释 ...... 详细 ...