org.freemarkerfreemarker2.3.20commons-loggingcommons" />

欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

利用freemarker做html頁面靜態化

系統 1791 0

背景:

對實時性要求不高的網站需要靜態化操作,那么我們基于freemarker做靜態化處理

環境:

      <dependency>
	<groupId>org.freemarker</groupId>
	<artifactId>freemarker</artifactId>
	<version>2.3.20</version>
</dependency>
<dependency>
	<groupId>commons-logging</groupId>
	<artifactId>commons-logging</artifactId>
	<version>1.1.1</version>
</dependency>
    

代碼實現:

模板文件:news.ftl

      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  
  <head>
    <title>
      ${article.title!}
    </title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <!-- <link rel="stylesheet" type="text/css" href="styles.css">  
    -->
  </head>
  
  <body>
    <h2>
      ${article.title!}
    </h2>
    <hr/>
    <pre>
      ${article.content}
    </pre>
  </body>
</html>
    

Java封裝類Article:

      public class Article  implements Serializable{
	private static final long serialVersionUID = 554206256994693476L;
	private String title;
	private String content;

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

}
    

注意:此類必須為public否則報freemarker.core.InvalidReferenceException

測試實現:

      public static void main(String[] ar) throws Exception, TemplateException {
	Configuration configuration = new Configuration();
	configuration.setEncoding(Locale.getDefault(), "UTF-8");
	TemplateLoader templateLoader = new FileTemplateLoader(new File("d:/"));
	configuration.setTemplateLoader(templateLoader);
	Template template = configuration.getTemplate("news.ftl");
	template.setEncoding("UTF-8");
	File file = new File("d:/news.html");
	Map<String, Article> rootMap = new HashMap<String, Article>();
	Article article = new Article();
	article.setTitle("關于小網客");
	article.setContent("解決方案咨詢<br>大數據處理<br>系統架構<br>企業信息化咨詢<br>Email:smallnetvisitor@qq.com<br>來自北京");
	rootMap.put("article", article);
	Writer out = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");

	template.process(rootMap, out);
}
    

?

說明:

此處采用了FileTemplateLoader,以D盤為根,寫的html頁面采用utf-8的編碼

結果如下圖:

?
利用freemarker做html頁面靜態化
?

?

利用freemarker做html頁面靜態化


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。?!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 久久精品91久久久久久再现 | 26uuu中文字幕 | 日韩在线免费电影 | 国产精品美女久久久久久免费 | 99热在线播放 | 91免费公开视频 | 欧美精品成人一区二区三区四区 | 天天摸天天爽视频69视频 | 国产中文字幕在线观看 | 国产美女被爽到高潮免费A片小说 | 日韩欧美在线视频 | 亚洲成人一区 | 日韩精品成人 | 久久久久久久久久亚洲 | 99久久精品国产一区二区三区 | 国产在线一区二区三区 | 热久久免费 | 日韩精品亚洲专区在线电影不卡 | 久久久免费视频观看 | 欧美成人一区二区 | 欧美a大片 | 日本人视频jizz69页码 | 欧美高清69hd | 午夜精品影院 | 九九99国产精品视频 | 激情视频免费在线观看 | 日本黄色大片免费看 | 99国产精品久久久 | 成人综合网站 | 丁香六月综合网 | 国产精品成熟老女人 | 免费国产免费福利视频 | 成人精品国产 | 性强烈欧美一级毛片 | 国产精品98福利小视频 | 在线观看免费av网 | 国产精品久久久久久久7电影 | 成人性视频免费网站 | 在线观看高清免费 | 一级片免费在线观看 | 一区二区三区在线 | 网站 |