首页 > 其他 > 详细

MyBatis XML 配置文件 properties 元素扩展

时间:2019-12-14 01:13:49      阅读:128      评论:0      收藏:0      [点我收藏+]

在分析 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 元素扩展

原文:https://www.cnblogs.com/lijianming180/p/12037716.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!