我正在尝试从常量文件中读取键值对。当我直接使用类名和字段名时它可以工作,但是当我动态构造Class+字段组合时它不起作用。如何协商这个问题?
以下是我的常量文件
Public interface Constants
{
String DEV_SELECT_STATEMENT = “DEV_INT_SQL_SELECT_STATEMENT”
String INT_SELECT_STATEMENT = “DEV_INT_SQL_SELECT_STATEMENT”
}
查询.properties 文件
DEV_INT_SQL_SELECT_STATEMENT = “SELECT * FROM SOME TABLE”;
JAVA类文件//这个工作
public someClass
{
public someMethod() //This works
{
String sqlStatement = QueryLoader.getStatement(Constants.DEV_SELECT_STATEMENT);
System.out.println("The key is :" + Constants. DEV_SELECT_STATEMENT);
System.out.println(“SqlStatement is : “ + sqlStatement);
}
}
关键是:DEV_INT_SQL_SELECT_STATEMENT
SqlStatement 是:SELECT * FROM SOME TABLE
public someClass //This does not work
{
public someMethod(String env) //This does not work
{
String queryKey = “Constants” +env + “_SELECT_STATEMENT “;
System.out.println(“The Key is : “ + queryKey);
String sqlStatement = QueryLoader.getStatement(queryKey);
System.out.println(“SqlStatement is : “ + sqlStatement);
}
Key is :Constants.DEV_SELECT_STATEMENT //这里不给值而是字符串
SqlStatement 是:空