讀取properties配置文件信息

響應示例

{

  "status": 0,

  "message": "成功",

  "data": {

    "comIncomeStatement": {

      "NETPROFITCOMS": "歸屬於母公司所有者的淨利潤",

      "CAPDEVELOPCOST": "研發費用",

      "OPEREXPENSE": "營業支出"

    },

    "comBalanceSheet": {

      "DEFERRTAXCREDITS": "遞延稅款貸項",

      "PAYMENTBUYBLANCES": "支付買入返售款項淨額",

      "CASHENDING": "現金的期末餘額"

    },

    "comCashflowStatement": {

      "INVTMTRECEIVABLE": "應收投資款項",

      "LESTREASURYSTOCK": "庫藏股",

      "SETTLEMENTPROVISION": "結算備付金"

    }

  }

}

返回數據格式如上,在properties配置中是常量形式的保存方式。

Service:

/**
 *  返回指標數的map形式接口
 * @return
 */
public Map findTreeJson(){
    try {
        Properties prop = new Properties();
        Properties prop2 = new Properties();
        Properties prop3=new Properties();
        InputStream in=CompanyService.class.getClassLoader().getResourceAsStream("properties/ComFinance/comCashflowStatement.properties");
        InputStream in2 = CompanyService.class.getClassLoader().getResourceAsStream("properties/ComFinance/comBalanceSheet.properties");
        InputStream in3 = CompanyService.class.getClassLoader().getResourceAsStream("properties/ComFinance/comIncomeStatement.properties");
        BufferedReader bf=new BufferedReader(new InputStreamReader(in,"gbk"));
        BufferedReader bf2=new BufferedReader(new InputStreamReader(in2,"gbk"));
        BufferedReader bf3=new BufferedReader(new InputStreamReader(in3,"gbk"));
        prop.load(bf);
        prop2.load(bf2);
        prop3.load(bf3);
        Map map = new HashMap();
        map.put("comCashflowStatement",prop);
        map.put("comBalanceSheet",prop2);
        map.put("comIncomeStatement",prop3);
        return map;
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
        throw new ServiceException(ResultEnum.ERROR.getCode(),"讀取properties配置出錯");
    }
}
Test.class.getClassLoader().getResource()方法,因爲該方法返回值是URL,這個方法在這邊不是獲取url不要使用,在jar包中路徑會出現問題~

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章