2019-01-03 21:18
@杜福忠 好 谢谢。那另外有个疑问
jfinal框架去启动插件的方法是在com.jfinal.core包的config类中吗?
private static void configPluginWithOrder(int order, JFinalConfig jfinalConfig) {
if (order == constants.getConfigPluginOrder()) {
jfinalConfig.configPlugin(plugins);
startPlugins(); // very important!!!
}
}
private static void startPlugins() { //这里是启动插件的吧
List pluginList = plugins.getPluginList();
if (pluginList == null) {
return ;
}
for (IPlugin plugin : pluginList) {
try {
// process ActiveRecordPlugin devMode
if (plugin instanceof com.jfinal.plugin.activerecord.ActiveRecordPlugin) {
com.jfinal.plugin.activerecord.ActiveRecordPlugin arp = (com.jfinal.plugin.activerecord.ActiveRecordPlugin)plugin;
if (arp.getDevMode() == null) {
arp.setDevMode(constants.getDevMode()); //但是这里不是只是设置了一下每个插件的setDevMode吗?并没用去调start()方法呀
}
}
if (plugin.start() == false) {
String message = "Plugin start error: " + plugin.getClass().getName();
log.error(message);
throw new RuntimeException(message);
}
}
catch (Exception e) {
String message = "Plugin start error: " + plugin.getClass().getName() + ". \n" + e.getMessage();
log.error(message, e);
throw new RuntimeException(message, e);
}
}
}
2019-01-03 20:31
@杜福忠
是不是在configPlugin(Plugins plugins) 中plugins.add(activeRecordPlugin),在configPlugin执行完后,jfinal框架去调用activeRecordPlugin中的start()方法,由于
activeRecordPlugin的start()中有
public boolean start() {
if (isStarted) {
return true;
}
所以我如果在configPlugin(Plugins plugins) 中手动.start() ,也不会重复启动
是这样吗?
2019-01-03 19:49
@杜福忠 jfinal中com.jfinal.core包的config类这里有判断只启动一次吗?
private static void startPlugins() {
List pluginList = plugins.getPluginList();
if (pluginList == null) {
return ;
}
for (IPlugin plugin : pluginList) {
try {
// process ActiveRecordPlugin devMode
if (plugin instanceof com.jfinal.plugin.activerecord.ActiveRecordPlugin) {
com.jfinal.plugin.activerecord.ActiveRecordPlugin arp = (com.jfinal.plugin.activerecord.ActiveRecordPlugin)plugin;
if (arp.getDevMode() == null) {
arp.setDevMode(constants.getDevMode());
}
}
if (plugin.start() == false) {
String message = "Plugin start error: " + plugin.getClass().getName();
log.error(message);
throw new RuntimeException(message);
}
}
catch (Exception e) {
String message = "Plugin start error: " + plugin.getClass().getName() + ". \n" + e.getMessage();
log.error(message, e);
throw new RuntimeException(message, e);
}
}
}
2018-12-29 13:15
@杜福忠 请教另外一个问题 现在可以启动就能获得到数据库的数据了,但是如果将这些数据赋值给一个自定义的枚举类?这样其他使用这个枚举类的都能获得这些数据?自定义枚举类:public enum Color {
YELLO("黄色", 4);//这里其实不应该有值,这里的值是项目启动时 从数据库读取出来的
private String name ;
private int index ;
private Color( String name , int index ){
this.name = name ;
this.index = index ;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getIndex() {
return index;
}
public void setIndex(int index) {
this.index = index;
}
}