田丽个人资料public class App {
//存储配置属性的Map集合
杜雨露主演的电视剧public static Map<String, Object> conf =new HashMap<String, Object>();
public static void main(String[] args)throws IOException {
//从classpath下获取配置⽂件路径
URL url = Resource("/l");
Yaml yaml =new Yaml();
读取配置文件失败//通过yaml对象将配置⽂件的输⼊流转换成map原始map对象
小型冰箱Map map = yaml.loadAs(new Path()), Map.class);
//递归map对象将配置加载到conf对象中
loadRecursion(map,"");中秋祝福语简短最火
System.out.("mysql.database1.table1"));
}
//递归解析map对象
public static void loadRecursion(Map<String, Object> map, String key){
map.forEach((k,v)->{
if(isParent(v)){
Map<String, Object> nextValue =(Map<String, Object>) v;
loadRecursion(nextValue,(("".equals(key)?"": key +".")+ k));
}else{
conf.put(key+"."+k,v);
}
});
}
//判断是否还有⼦节点
public static boolean isParent(Object o){
if(!(o instanceof String || o instanceof Character || o instanceof Byte)){
try{
Number n =(Number) o;
}catch(Exception e){
return true;
}王思聪在哪直播
}
return false;
}
}
发布评论