-
-
-
-
-
-
- package freemarker.loader;
-
- import java.io.IOException;
- import java.io.Reader;
- import java.io.StringReader;
-
- import freemarker.cache.TemplateLoader;
-
-
-
-
-
-
- public class StringTemplateLoader implements TemplateLoader {
-
- private String template;
-
- public StringTemplateLoader(String template){
- this.template = template;
- if(template == null){
- this.template = "";
- }
- }
-
- public void closeTemplateSource(Object templateSource) throws IOException {
- ((StringReader) templateSource).close();
- }
-
- public Object findTemplateSource(String name) throws IOException {
- return new StringReader(template);
- }
-
- public long getLastModified(Object templateSource) {
- return 0;
- }
-
- public Reader getReader(Object templateSource, String encoding)
- throws IOException {
- return (Reader) templateSource;
- }
-
- }
-
-
-
-
-
-
-
- package freemarker;
-
- import java.io.File;
- import java.io.OutputStreamWriter;
- import java.io.StringWriter;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.Map;
-
- import freemarker.loader.ClassPathTemplateLoader;
- import freemarker.loader.StringTemplateLoader;
- import freemarker.template.Configuration;
- import freemarker.template.Template;
-
-
-
-
-
-
- public class Test {
-
- public static void main(String[] args) throws Exception {
- Configuration cfg = new Configuration();
- cfg.setTemplateLoader(new StringTemplateLoader("欢迎:${user}"));
- cfg.setDefaultEncoding("UTF-8");
-
- Template template = cfg.getTemplate("");
-
- Map root = new HashMap();
- root.put("user", "Keven Chen");
-
- StringWriter writer = new StringWriter();
- template.process(root, writer);
- System.out.println(writer.toString());
- }
-
- }
分享到:
相关推荐
NULL 博文链接:https://zhenghuazhi.iteye.com/blog/1923544
里面 集合了 一个 简单的 Freemarker demo 代码 和一个 freemarker 自定义标签代码
freemarker实现自动补...通过ftl模版文件(ftl文件为freemarker模版文件)的自定义标签实现自动补齐字符串。代码稍作修改便可左补齐右补齐左右补齐,可自定义设置补齐的字符串。测试通过java文件调用ftl文件显示结果。
NULL 博文链接:https://bijian1013.iteye.com/blog/2259856
spring mvc freemarker 自定义标签demo spring mvc 通过自定义的标签在jsp页面调用,初学,记录下做个备忘
一个用FTL定义的非常通用数据分页指令,有源码,有使用示例。使用效果图可以参看本人博客中的相关文章:http://blog.csdn.net/qjyong/archive/2009/10/18/4693142.aspx
纯java的文本解析模板,如可解析SQL语句,解析Excel中动态内容
FreeMarker的模板文件并不比HTML页面复杂多少,FreeMarker模板文件主要由如下4个部分组成: 1,文本:直接输出的部分 2,注释:格式部分,不会输出 3,插值:即${...}或#{...}格式的部分,将使用数据模型中的部分替代输出 4,...
ant + freemarker + excel解析
NULL 博文链接:https://asialee.iteye.com/blog/2062313
在jfinal的基础上,实现freemarker自定义标签的自动扫描和注册,本资源包不含jfinal框架,需在已有框架的基础上添加包中的代码,如需jfinal框架请自行到官网下载
Freemarker_内置函数_数字、字符串、日期格式化.txt
NULL 博文链接:https://renxin-327666062-qq-com.iteye.com/blog/1532731
NULL 博文链接:https://hw1287789687.iteye.com/blog/2271501
字符串 Freemarker代码 <#switch being.size> <#case "small"> This will be processed if it is small <#break> <#case "medium"> This will be processed if it is medium <#break> ...
freemarker大致原理是:将页面中所需要的样式放入FreeMarker文件中,然后将页面所需要的数据动态绑定,并放入Map中,通过调用FreeMarker模板文件解析类process()方法完成静态页面的生成。了解了上面的原理,接下来我...
Spring配置Freemarker视图解析器,配置多个视图解析器
该例采用单元测试,实现fremarker通用下拉框,满足所有web下拉框需求
spring boot + mybaits +freemarker +maven 架构来袭 注解版 spring boot + mybaits +freemarker +maven 架构来袭 注解版
Spring配置Freemarker视图解析器,前台页面全部使用freemarker渲染