2017-08-04 09:15
@JFinal 也就是说网上有一些人提到的,在controler中注入service
public abstract class Controller extends com.jfinal.core.Controller {
public Controller(){
Field[] fields =this.getClass().getDeclaredFields();
for (int i=0;i < fields.length; i++){
Field field = fields[i];
Class clazz = field.getType();
if(Service.class.isAssignableFrom(clazz) && clazz != Service.class){
try {
field.set(this, Service.getInstance(clazz, this));
} catch (IllegalAccessException e) {
Log.e(e);
}
}
}
}
},实际是不应该这么做的,而是应该
在controler中private AccountService srv = AccoutService.me;
是吗?