Using Freemark to generate static HTML pages

Source: Internet
Author: User

  <!--freemarker template jar-related dependencies-        <dependency>            <groupid>org.freemarker</ groupid>            <artifactId>freemarker</artifactId>            <version>2.3.20</version>        </dependency>
 PackageCom.jy.common.util;Importfreemarker.template.Configuration;Importfreemarker.template.Template;ImportJava.io.File;ImportJava.io.FileOutputStream;ImportJava.io.OutputStreamWriter;ImportJava.io.Writer;ImportJava.util.HashMap;ImportJava.util.Map;/*** Created by JY on 2018/3/21.*/ Public classFreemarkerutil { Public Static voidMain (string[] args) {createhtml ();    }     Public Static voidCreatehtml (String modelpath,string modelname,map<string,object>map) {Configuration cfg=NewConfiguration (); Try {            //cfg.setdirectoryfortemplateloading (New File ("c:/my/aaa/bbb")); //set directory to read template filesCfg.setdirectoryfortemplateloading (NewFile (Modelpath));//set directory to read template files//Template t = cfg.gettemplate ("INDEX.FTL"); //read a template with the file name TEST.FTLTemplate t = cfg.gettemplate (modelname);//read a template with the file name INDEX.FTLMap Root=NewHashMap ();//Storing DataRoot.put ("id", 1); Root.put ("Name", "Zhangsan"); Writer out=NewOutputStreamWriter (NewFileOutputStream ("C:/my/aaa/bbb/a.html"), "UTF-8");//output Streamt.process (root, out);//dynamically load the data in root to test.html.            The data is defined in the template. //t.process (map, out);//dynamically load the data in root to test.html. The data is defined in the template. }Catch(Exception e) {} System.out.println ("Create successfully!"); }}

Using Freemark to generate static HTML pages

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.