后台内容添加以后就不改变了.而且添加内容也是手动添加.
现在有一问题,就是查询的时候,得先到资源文件里找value的值,然后根据value的值再在资源文件里找对应的key值,然后再根据key到数据库中找对应此key的id并把id取出来做成超链接.
请问,如何在资源文件里找value呢?再就是找到value后再怎么找key呢? 想了好多天了.网上也没有相关资料.
我想到一个办法,还没测试.只是写了一下代码.
public List getKeys(String selectName,String bundleName){
ArrayList keys = null;
ResourceBundle bundle = ResourceBundle.getBundle("com.store.struts." + bundleName);
List keyList = (List)bundle.getKeys();//获取bundle中所有的键值.
Iterator iter = keyList.iterator();
String key = null;
/*
* 遍历键值表,找出键值对应value与selectName相同,或selectName是value子串的key.添加到keys里
*/
while(iter.hasNext()){
key = (String)iter.next();
String value = bundle.getString(key);
if(value.contains(selectName) || value == selectName || value.equals(selectName) ){
keys.add(key);
}
}
return keys;//返回所需的键值表.
}
/*
* 判断该执行哪一个bundle来获取keys表.
*
*/
/**
* @return keys
*/
public List judgeBundle(HttpServletRequest request , String selectName){
List keys = null;
Locale locale = request.getLocale();
String country= locale.getCountry();
if(country.equalsIgnoreCase("zh")){
keys = getKeys(selectName,"ApplicationResource_zh");
}
else if(country.equalsIgnoreCase("en")){
keys = getKeys(selectName,"ApplicationResource_en ");
}
else{
keys = getKeys(selectName,"");
}
return keys;
}
bu不知道这样能不能行.