有关门面模式和ResourceBundle的问题,急。
现在我写了两个类,
package com.kikuya.wes.logic;
public interface WesFacade {
String getMessage(String strName);
}
package com.kikuya.wes.logic;
import java.util.Locale;
import java.util.ResourceBundle;
public class WesFacadeImpl implements WesFacade {
private ResourceBundle rb;
public void setRb(ResourceBundle rb) {
this.rb = rb;
}
public String getMessage(String strName) {
if (strName.equalsIgnoreCase( "wespath ")) {
return rb.getString(strName);
} else if (strName.equalsIgnoreCase( "uploadfilepath ")) {
return rb.getString(strName);
} else if (strName.equalsIgnoreCase( "uploadpicturepath ")) {
return rb.getString(strName);
} else if (strName.equalsIgnoreCase( "savehtmlpath ")) {
return rb.getString(strName);
}
return null;
}
public static void main(String[] args){
ResourceBundle rb = ResourceBundle.getBundle( "fileposition_zh_CN.properties ",Locale.CHINA);
WesFacadeImpl wesImpl = new WesFacadeImpl();
wesImpl.setRb(rb);
System.out.println(wesImpl.getMessage( "uploadfilepath "));
}
}
用Spring的依赖注入,怎么样能从多个资源文件中获取值呢?麻烦指教一下。
------解决方案--------------------ResourceBundle是根据客户端的Locale来判断用哪个资源文件的,或者你根据用户的某些信息来判断用哪个资源文件,ResourceBundle rb = ResourceBundle.getBundle( "fileposition_zh_CN.properties ",Locale.CHINA);
这里不要写死。