public static void main(String[] args) throws IOException, TemplateException {
//1.创建一个Configuration对象
Configuration configuration = new Configuration(Configuration.getVersion());
//2.设置模板文件使用的字符集
configuration.setDefaultEncoding(\"utf-8\");
//3.设置模板文件所在的目录
configuration.setDirectoryForTemplateLoading(new File(\"F:\\\\IdeaProjects\\\\spring-data-redis\\\\freemarker_01\\\\src\\\\main\\\\resources\"));
//4.加载一个模板,创建一个模板对象
Template template = configuration.getTemplate(\"test.ftl\");
//5.创建一个模板使用的数据集
Map map = new HashMap();
map.put(\"name\", \"程序员\");
map.put(\"message\", \"欢迎来到fr
/dependency>
(2)创建模板文件
模板文件中四种元素
1、文本,直接输出的部分
2、注释,即<#--...-->格式不会输出
3、插值(Interpolation):即${..}部分,将使用数据模型中的部分替代输出
4、FTL指令:FreeMarker指令,和HTML标记类似,名字前加#予以区分,不会输出。
test.ftl
<html>
<head>
< charset=\"utf-8\">
< >Freemarker入门小Demo </ >
</head>
<body>
<#--我只是一个注释,我不会有任何输出 -->
${name},你好。${message}<br/>
</body>
</html>
eemarker静态页面\");
//6.创建输出流
FileWriter writer = new FileWriter(\"f:\\\\test.html\");
//7.输出模板文件
template.process(map, writer);
//8.关闭流
writer.close();
}
继续阅读与本文标签相同的文章
爱普生“冷印”技术来袭 引领打印“酷”时代
-
使用nginx部署网站
2026-05-18栏目: 教程
-
Java的四种线程池的使用,以及自定义线程工厂
2026-05-18栏目: 教程
-
Leetcode之删除排序数组中的重复项
2026-05-18栏目: 教程
-
详细领悟ThreadLocal变量
2026-05-18栏目: 教程
-
MyBatis的底层实现原理!是动态代理的运用~
2026-05-18栏目: 教程
