@IocBean
public class DictTag extends GeneralVarTagBinding {
String name,value,style,dictType;
String type = "checkbox";
StringBuffer sb = new StringBuffer();
@Inject
MacroService macroService;
private void init() {
name = (String)getAttributeValue("name");
value = (String)getAttributeValue("value");
style = (String)getAttributeValue("style");
dictType = (String)getAttributeValue("dictType");
type = (String)getAttributeValue("type");
}
@Override
public void render() {
init();
List<Macro> list = macroService.listByDictType(dictType);
}
}
这里会报空指针异常,没有找到marcoService ,而下面这样写就是对的
public class DictTag extends GeneralVarTagBinding {
String name,value,style,dictType;
String type = "checkbox";
StringBuffer sb = new StringBuffer();
MacroService macroService;
private void init() {
Ioc ioc = Mvcs.getIoc();
name = (String)getAttributeValue("name");
value = (String)getAttributeValue("value");
style = (String)getAttributeValue("style");
dictType = (String)getAttributeValue("dictType");
type = (String)getAttributeValue("type");
macroService = ioc.get(MacroService.class);
}
@Override
public void render() {
init();
List<Macro> list = macroService.listByDictType(dictType);
}
}