读取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包中路径会出现问题~

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