在分析 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 1048 Find Coins (25) [Hash散列]

    题目 Eva loves to collect coins from all over the universe, including some other planets like Mars. On ...

  2. UML-如何画SSD?

    1.SSD来自哪里?答:用例文本 2.如何为系统事件和操作命名? 3.SSD中的哪些需要放到词汇表中? SSD元素包含 1).操作名称 2).参数 3).返回数据 这些元素,必须要简洁.但别人可能不太 ...

  3. ios 真机使用相机闪退问题

    需要增加权限 在info文件增加 主要前面的key 后面的cameraDesciption只是一段描述 随便写就可以

  4. oauth2 Spring Security

    oauth2四种授权方式小结 http://www.ruanyifeng.com/blog/2019/04/oauth-grant-types.html 密码模式(resource owner pas ...

  5. servlet 上传文件

    java protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException ...

  6. Monkey日常测试命令

    一,LOG日志抓取 adb  logcat -b main -v time >log.txt --实时日志打印 adb shell monkey -p com.eeyescloud.eeyes  ...

  7. 项目课 day02.1

    JWT - json-web-token json.dumps(d,separators = (',' , ':')) separators:分隔符,键值对之间  ,相连, jwt.encode({' ...

  8. script和scriptreplay_超骚气的实时监控你的服务器

    今天看到一个超级叼的linux命令,可以完整记录屏幕上的命令与输出结果. 有人问这有什么叼的,不就是保存历史操作记录吗?我看看日志也能看出来. 不不不,我要说的“完整记录”包括第几秒执行什么命令,就像 ...

  9. 自定义字段从BOM带入生产用料清单

    自定义字段从BOM带入生产用料清单

  10. 记录ionic 最小化应用时所遇的问题

    ionic3与ionic4最小化插件安装不一样: ionic3安装方法: $ ionic cordova plugin add cordova-plugin-appminimize $ npm ins ...