概述
如何做一个freemaker模版,并打印到system栏?
导入所需jar包。
在src目录下创建一个文件夹:ftl
在ftl下创建模版文件 01.ftl
你好:${username}package eeeee;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
public class Rr{
public Template getTemplate(String name )
{
try {
Configuration configuration = new Configuration() ;
//设置模版的文件夹路径,“当前类路径+/ftl”
configuration.setClassForTemplateLoading(this.getClass(),"/ftl");
//获得模版(模版名)
Template template = configuration.getTemplate(name);
return template;
} catch (IOException e) {
e.printStackTrace();
}
return null ;
}
// 根据模版名 和 参数键值对map,打印模版。
public void print2Console(String name , Map root)
{
try {
Template template = getTemplate(name);
// 此模版根据root处理,到系统打印台。
cess(root, new PrintWriter(System.out));
} catch (TemplateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args)
{
Rr rr= new Rr() ;
Map root = new HashMap();
root.put("username", "张鸿洋");
.print2Console("01.ftl", root);
}
}
如何做一个freemaker模版,并传到d盘中的dd.html文件?
package eeeee;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
public class Uu{
public Template getTemplate(String name )
{
try {
Configuration configuration = new Configuration() ;
//设置模版存放的文件夹路径,为 “当前类路径+/ftl”
configuration.setClassForTemplateLoading(this.getClass(),"/ftl");
//获得模版(模版名)
Template template = configuration.getTemplate(name);
return template;
} catch (IOException e) {
e.printStackTrace();
}
return null ;
}
public void print2File(String name , Map
最后
以上就是内向豌豆为你收集整理的html freemaker 遍历,freemaker的使用.doc的全部内容,希望文章能够帮你解决html freemaker 遍历,freemaker的使用.doc所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复