后台全局配置界面
设计了一个全局配置类,可以在模板中直接使用,后台修改之后调用set方法,可实时更新配置。
/**
* 读取系统配置
*/
public class Config {
private static Config instance = null;
private static Map<String, String> map = null;
static SysConfigService srv = SysConfigService.me;
private Config() {
map = srv.getSysConfigMap();//数据库读取所有配置项
}
public static synchronized Config me() {
if (instance == null) {
instance = new Config();
}
return instance;
}
public String get(String key) {
return map.get(key);
}
public Integer getInt(String key) {
String value = get(key);
if (value != null) {
return Integer.valueOf(value);
}
return null;
}
public Boolean getBoolean(String key) {
String value = get(key);
if (value != null) {
return Boolean.valueOf(value);
}
return null;
}
public static void set(String key,String value) {
map.put(key,value);
}
}configEngine中
me.addSharedObject("cfg", Config.me());模板中使用
#(cfg.get("application.name"))代码中使用
String defaultPassword = Config.me().get("system.default.password");
楼主的全局配置在模板中的使用方式非常简洁,感谢你的分享