package com.ag.util;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.ResourceBundle;

/**
 * Created by yangxh on 2019/8/27.
 */
public class ResourceUtil {
    private static Log log = LogFactory.getLog(ResourceUtil.class);

    /**
     * 根据配置文件路径和key，获取配置参数
     * @param key
     * @param configPath
     * @return
     */
    public static String getString(String configPath, String key) {
        //如果配置文件唯一，可以在类中把configPath成名为常量，把ResourceBundle对象声明为全局静态变量
        ResourceBundle resourceBundle = getResourceBundle(configPath);
        return resourceBundle.getString(key);
    }

    public static ResourceBundle getResourceBundle(String configPath){
        return ResourceBundle.getBundle(configPath);
    }

    public static String getString(ResourceBundle rb, String key){
        return rb.getString(key);
    }

}
