NutzCN Logo
问答 nutzboot 中使用beetl,定义beetl的全局变量,我是直接把官网的代码拿过来的,可是标签还是说没有定义?
发布于 2193天前 作者 小苍蝇 2394 次浏览 复制 上一个帖子 下一个帖子
标签: nutzwk

我定义了一个ctx标签,页面上不能获取,说没有定义

/**  
 * @author chi
 * 启动主类
 */
@IocBean(create="init")
public class MainLauncher {
	
	@Inject 
	Dao dao;
	@Inject
	Ioc ioc;
	
    public void init() {
    	//自动把每个bean建成表,com.thinkingstar.iads下所有的bean文件
    	Daos.createTablesInPackage(dao, "com.thinkingstar.iads", false);
    	//beetl初始化全局变量
		try {
			StringTemplateResourceLoader resourceLoader = new StringTemplateResourceLoader();
			Configuration cfg = Configuration.defaultConfiguration();
			GroupTemplate gt = new GroupTemplate(resourceLoader, cfg);
			Map<String,Object> shared = new HashMap<String,Object>();
			shared.put("ctx", "beetl");
			gt.setSharedVars(shared);
		} catch (IOException e) {
			e.printStackTrace();
		}
    	
    }
    

    public static void main(String[] args) throws Exception {
        new NbApp().setArgs(args).setPrintProcDoc(true).run();
    }
2 回复
     @Inject
     GroupTemplate groupTemplate;

    public void init() {
    	//自动把每个bean建成表,com.thinkingstar.iads下所有的bean文件
    	Daos.createTablesInPackage(dao, "com.thinkingstar.iads", false);
    	//beetl初始化全局变量
		try {
			Map<String,Object> shared = new HashMap<String,Object>();
			shared.put("ctx", "beetl");
			groupTemplate.setSharedVars(shared);
		} catch (IOException e) {
			e.printStackTrace();
		}
    	
    }

添加回复
请先登陆
回到顶部