1. 程式人生 > >讀取字尾(yml)配置檔案

讀取字尾(yml)配置檔案

步驟:

1、

-
  id: 'a'
  name: 餐廳
  level: '1'
-
  id: 'a0'
  name: 肯德基
  pId: 'a'
  level: '2'
-

注意:漢字不能讀取時加單引號

2、引入yaml-integration-1.1.1.jar包

3、public List<Map<String, Object>> loadLeftTree(HttpServletRequest request) {
List<Map<String, Object>> resultList = new ArrayList<>();
try {
Yaml yaml = new Yaml();
String path = "leftTree.yml";
URL url = CaseRelatedServiceImpl.class.getClassLoader().getResource(path);
if(null != url){
resultList = (List<Map<String, Object>>)yaml.load(new FileInputStream(url.getFile()));
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return resultList;
}