字符串作为freemarker模板
来源:互联网 发布:苹果手机数据找回 编辑:程序博客网 时间:2024/05/21 10:49
package com.test.demo; import java.io.IOException; import java.io.StringWriter; import java.util.HashMap; import java.util.Map; import freemarker.cache.StringTemplateLoader; import freemarker.template.Configuration; import freemarker.template.Template; import freemarker.template.TemplateException; public class TestFreemarker { /** * @param args */ public static void main(String[] args) { Configuration cfg = new Configuration(); StringTemplateLoader stringLoader = new StringTemplateLoader(); String templateContent="欢迎:${name}"; stringLoader.putTemplate("myTemplate",templateContent); cfg.setTemplateLoader(stringLoader); try { Template template = cfg.getTemplate("myTemplate","utf-8"); Map root = new HashMap(); root.put("name", "javaboy2012"); StringWriter writer = new StringWriter(); try { template.process(root, writer); System.out.println(writer.toString()); } catch (TemplateException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
/** * getControlOptions: 渲染字符串dataOptions<br/> * @param options * @param m * @return * String * @exception * @since 1.0.0 */ private static String getControlOptions(String options, Map<String, Object> m) { if(StringUtils.isNoneBlank(options)){ Configuration config = new Configuration(Configuration.VERSION_2_3_23); StringTemplateLoader stringTemplate = new StringTemplateLoader(); String templateName = "formOptions"; stringTemplate.putTemplate(templateName,options); config.setTemplateLoader(stringTemplate); Writer out = new StringWriter(256); try { Template template = config.getTemplate("formOptions","utf-8"); template.process(m, out); } catch (TemplateException | IOException e) { e.printStackTrace(); } return out.toString(); } return options; }
0 0
- 字符串作为freemarker模板
- 字符串作为freemarker模板的简单实现例子
- java 字符串作为freemarker模板的简单实现例子
- 字符串作为freemarker模板的简单实现例子
- 字符串作为freemarker模板的简单实现例子
- FreeMarker解析字符串模板
- FreeMarker解析字符串模板
- 【转载】FreeMarker解析字符串模板
- 采用freemarker模板引擎作为Java邮件模板
- 使用FreeMarker模板引擎作为Struts2的视图技术
- Freemarker通过字符串变量创建模板
- Map变为字符串的FreeMarker模板实现
- C++ template -- 字符串作为函数模板实参
- 使用字符串作为函数模板的实参
- Notes-6:字符串常量作为模板参数
- 字符串常量作为模板参数的陷阱
- freemarker 模板
- FreeMarker模板
- 记住密码?so easy!
- HTTP Status 500 - /dologin.jsp (line: 27, column: 3) Expecting "jsp:param" standard action with "nam
- 公司禁端口环境下上网
- Python 小练习题集
- 日志组件logback的介绍及配置使用方法
- 字符串作为freemarker模板
- JavaScript中prompt的使用
- delete崩溃
- C++软件开发学习目录
- pull,sax,dom解析XML
- 使用 Google Fonts 为网页添加美观字体
- iwebshop全选、反选、批删、即点即改
- PTA:两个有序链表的合并解题报告
- 从一串字符串中找到第一个不重复的字母