package com.learn.chapter2.test;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Properties;
import org.apache.ibatis.io.Resources;
public class ReadXMLandProperties {
@SuppressWarnings("unused")
public static void main(String[] args) {
InputStream cfgStream = null;
Reader cfgReader = null;
InputStream proStream = null;
Reader proReader = null;
Properties properties = null;
try{
//读取配置文件
cfgStream = Resources.getResourceAsStream("mybatis-config.xml");
cfgReader = new InputStreamReader(cfgStream);
//读取属性文件
proStream = Resources.getResourceAsStream("jdbc.properties");
proReader = new InputStreamReader(proStream);
properties.load(cfgStream);
//解密为明文
properties.setProperty("username", decode(properties.getProperty("username")));
properties.setProperty("password", decode(properties.getProperty("password")));
}catch (Exception e) {
// TODO: handle exception
}
}
private static String decode(String str){
//解密
return str;
}
}
Mybatis学习之读取配置文件(三)
最新推荐文章于 2024-04-26 04:00:00 发布
本文展示了一个Java程序,该程序使用MyBatis框架提供的Resources工具类来读取mybatis-config.xml配置文件和jdbc.properties属性文件,并将读取到的内容加载到Properties对象中。此外,还展示了如何对敏感信息进行简单的解密处理。
1012

被折叠的 条评论
为什么被折叠?



