在分析 MyBatis XML 配置文件 properties 元素时提到了三种配置方式,其中 property 子元素 和 properties 文件都比较容易理解,但是为什么还要提供一种代码参数传递的方式呢?

假设一种使用场景,生产环境的数据库联系方式是加密的,故需要 jdbc.properties 文件中以密文的形式保存,而 MyBatis 默认不支持直接解密读取,此时就需要程序进行解密读取。

1
2
3
4
5
6
7
8
9
10
String configResource = "mybatis-config.xml";
InputStream configInputStream = Resources.getResourceAsStream(configResource);

大专栏  MyBatis XML 配置文件 properties 元素扩展>String propertiesResource = "jdbc.properties";
InputStream propertiesInputStream = Resources.getResourceAsStream(propertiesResource);
Properties properties = new Properties();
properties.load(propertiesInputStream); properties.setProperty(decode(properties.getProperty("key")));
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream, properties);

实现解密方法:

1
2
3
private String decode(String value) {
// TODO
}

这里只是介绍一种使用思路

MyBatis XML 配置文件 properties 元素扩展的更多相关文章

  1. mybatis基础,mybatis核心配置文件properties元素

    peroperties元素 可外部配置且可动态替换的,既可以在典型的 Java 属性文件中配置,亦可通过 properties 元素的子元素来传递 为dataSource元素配置 <proper ...

  2. mybatis xml配置文件模版

    mybatis xml配置文件模版 1.mybatis核心配置文件书写(SqlMapConfig.xml) <?xml version="1.0" encoding=&quo ...

  3. MyBatis Generator配置文件context元素的defaultModelType属性

    MyBatis Generator配置文件context元素的defaultModelType属性 MyBatis Generator配置文件context元素有一个defaultModelType属 ...

  4. MyBatis XML配置properties

    来源:https://www.w3cschool.cn/mybatis/7zy61ilv.html XML 映射配置文件 MyBatis 的配置文件包含了影响 MyBatis 行为甚深的设置(sett ...

  5. mybatis xml配置文件要点说明

    mapper映射方式: 1 一一具体列举的方式 2扫描package 如: <mappers> <!-- 告知映射文件方式1,一个一个的配置 <mapper resource= ...

  6. spring+springmvc+mybatis xml配置文件

    一.jdbc.properties 文件: driver=com.mysql.jdbc.Driverurl=jdbc:mysql://192.168.31.xxx:3306/abc?useUnicod ...

  7. Mybatis XML 配置文件

    <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC ...

  8. spring xml配置文件根元素(文件头文件)说明

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  9. MyBatis xml配置文件详解

    http://blog.csdn.net/fenghuibian/article/details/52525671

随机推荐

  1. PAT Advanced 1092 To Buy or Not to Buy (20) [Hash散列]

    题目 Eva would like to make a string of beads with her favorite colors so she went to a small shop to ...

  2. [原]调试实战——使用windbg调试DLL卸载时的死锁

    原调试debugwindbg死锁deadlock 前言 最近我们的程序在退出时会卡住,调查发现是在卸载dll时死锁了.大概流程是这样的:我们的dll在加载的时候会创建一个工作线程,在卸载的时候,会设置 ...

  3. Go-map-字符串-指针-结构体

    Maps 什么是 map ? 类似Python中的字典数据类型,以k:v键值对的形式. map 是在 Go 中将值(value)与键(key)关联的内置类型.通过相应的键可以获取到值. 如何创建 ma ...

  4. 【转】Rendering Problems The following classes could not be instantiated

    xml 设计时警告 打开es/values/目录下styles.xml文件. 把:<style name="AppTheme" parent="Theme.AppC ...

  5. cygwin下命令行下切换目录

    比我们正常切换目录多个挂载的文件夹 cygdrive

  6. HDU 1257最少拦截系统[动态规划]

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1257                                                 最 ...

  7. Python笔记_第一篇_面向过程_第一部分_5.Python数据类型之集合类型(set)

    集合!Python中的集合数据基本上是为了方便数学计算使用的. 什么是集合? 集合就是“确定的一堆东西”.集合里面的东西叫做元素. 特点:1. 集合里面是没有重复的元素的.           2. ...

  8. 基于JSP+Servlet开发在线租车系统 java 源码

    运行环境: 最好是java jdk 1.8,我们在这个平台上运行的.其他版本理论上也可以.IDE环境: Eclipse,Myeclipse,IDEA都可以tomcat环境: Tomcat 7.x,8. ...

  9. 吴裕雄--天生自然 JAVA开发学习:重写(Override)与重载(Overload)

    class Animal{ public void move(){ System.out.println("动物可以移动"); } } class Dog extends Anim ...

  10. HTTP1.0和HTTP1.1的一些区别

    HTTP1.0和HTTP1.1的一些区别 HTTP1.0最早在网页中使用是在1996年,那个时候只是使用一些较为简单的网页上和网络请求上,而HTTP1.1则在1999年才开始广泛应用于现在的各大浏览器 ...