beetl 在spring mvc里没有做整合,当工具这样用会不会有性能问题

weixin_38058428 2017-12-20 11:21:04
@Autowired GetModeDataFunction getModeDataFunction; @Autowired GetUserPageFunction getUserPageFunction; @Autowired TemplateUtilFunction templateUtilFunction; private WebAppResourceLoader resourceLoader = null; private StringTemplateResourceLoader resourceLoader_str = null; private Configuration cfg = null; private GroupTemplate gt = null; private GroupTemplate gt_str = null; //构造方法 public IndexSession() throws IOException { resourceLoader = new WebAppResourceLoader(); resourceLoader_str = new StringTemplateResourceLoader(); cfg = Configuration.defaultConfiguration(); gt = new GroupTemplate(resourceLoader, cfg);//处理文件模板 gt_str = new GroupTemplate(resourceLoader_str, cfg);//处理字符串模板 } /**给模板添加公共的东西 * @param request */ private void setBeetlTemplate(HttpServletRequest request) { //设置模板全局变量,path和basePath Map<String,Object> map = new HashMap<String,Object>(); String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getLocalAddr() + ":" + request.getServerPort() + path; map.put("path", path); map.put("basePath", basePath); //处理文件模板 if(CoreUtils.isEmpty(gt.getSharedVars())) {//如果已经设置过,就不重复设置了 gt.setSharedVars(map);//设置全局变量 gt.registerFunction("listDataService", getModeDataFunction);//添加自定义函数 gt.registerFunction("getUserPage", getUserPageFunction);//获取自编页面地址 gt.registerFunction("templateUtil", templateUtilFunction);//显示控制 } //处理字符串模板 if(CoreUtils.isEmpty(gt_str.getSharedVars())) {//如果已经设置过,就不重复设置了 gt_str.setSharedVars(map);//设置全局变量 gt_str.registerFunction("listDataService", getModeDataFunction);//添加自定义函数 gt_str.registerFunction("getUserPage", getUserPageFunction);//获取自编页面地址 gt_str.registerFunction("templateUtil", templateUtilFunction);//显示控制 } } Template t = gt.getTemplate("/beetlTemplate/xxx.html"); Template t_text = gt_str.getTemplate(""); @闲大赋 你好,想跟你请教个问题: spring mvc 里这样用会不会有性能问题  
...全文
54 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_38073288 2017-12-20
  • 打赏
  • 举报
回复
GroupTemlate是重量级对象,不要初始化多个就行

476

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧