freemarker
发布日期:2021-05-14 13:23:21 浏览次数:15 分类:精选文章

本文共 3370 字,大约阅读时间需要 11 分钟。

���: ������

Web���������������������JSP���������������������������������������JSP���������������������Java���������Servlet���������������������������HTML������������������������������������������������������������������������������JSP���������Java������������������������������FreeMarker������������������������������������������������

FreeMarker���������������Java���������������������������������������������������������������Web���������������FreeMarker���������������Servlet���HTTP���������������������������������������������������������������������������������������������������������������������/XML���JSP���Java���������������������������������������������������������������������������������������������

���: Freemarker���Helloworld

������������������������������������������������Freemarker������������������������������������������������

your_project/
��������� src/
��� ��������� main/
��� ��������� webapp/
��� ��������� WEB-INF/
��� ��� ��������� ftl/
��� ��� ��������� hello.ftl
��� ��������� freemarker/
��� ��������� version/
��� ��������� freemarker.jar
��������� pom.xml

���������������FreeMarker���������������������������������������������������ftl������������������

������������������

���webapp/WEB-INF/ftl���������������hello.ftl���������������

������:${title}

������������

������������pom.xml���������������������������

org.freemarker
freemarker
2.3.23

������������������������

������������������������������������������������������������

import org.freemarker.Configuration;
public class FreemarkerHelloWorld {
public String getHtml() throws Exception {
Configuration configuration = new Configuration(Configuration.getVersion());
configuration.setDirectoryForTemplateLoading(new File("D:/workspaces/freemarker-test/src/main/webapp/WEB-INF/ftl"));
configuration.setDefaultEncoding("utf-8");
Template template = configuration.getTemplate("hello.ftl");
Map
dataModel = new HashMap<>();
dataModel.put("title", "���������������������Freemarker������");
Writer out = new FileWriter(new File("D:/temp/term197/out/hello.html"));
template.process(dataModel, out);
out.close();
return "������������������������ /D:/temp/term197/out/hello.html";
}
}

���: Freemarker������������

1. ������Map���������

������������������$���������������������

${key}

2. ������POJO������������

${stu.id} - ${stu.name}

3. ���������������������

<#list studentList as student>
<#if student_index % 2 == 0>
������������
<#else>
������������

4. ������������

<#if student_index % 2 == 0>
������������
<#else>
������������

5. ���������������

${date?date} 2016-9-13
${date?time} 17:53:55
${date?datetime} 2016-9-13 17:53:55
${date?string("yyyy/MM/dd")}

6. Null���������

���������������������������������������������������������������!���������������������

${aaa!"���������"}
������
${aaa!}

7. ���������������������

������������������������������������������

<#include "���������������.ftl">

���: Spring Boot������Freemarker

������������������������������������������������������������������������������������FreeMarker���������

上一篇:ubuntu 16.04无法连接网络;双系统无法上网;连接已断开,你现在处于断开状态
下一篇:jsp使用

发表评论

最新留言

路过,博主的博客真漂亮。。
[***.116.15.85]2025年04月15日 12时23分00秒