Created
March 5, 2015 16:54
-
-
Save franzwong/c4913bd00af4ea35564b to your computer and use it in GitHub Desktop.
freemarker quickstart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.franzwong.codepiece.java.freemarker.freemarker001; | |
public class DataModel { | |
private String name; | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
this.name = name; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.franzwong.codepiece.java.freemarker.freemarker001; | |
import java.io.OutputStreamWriter; | |
import java.io.Writer; | |
import freemarker.cache.ClassTemplateLoader; | |
import freemarker.cache.TemplateLoader; | |
import freemarker.template.Configuration; | |
import freemarker.template.Template; | |
import freemarker.template.TemplateExceptionHandler; | |
public class MainApplication { | |
public static void main(String[] args) throws Exception { | |
TemplateLoader templateLoader = new ClassTemplateLoader(MainApplication.class, "/"); | |
Configuration cfg = new Configuration(Configuration.VERSION_2_3_22); | |
cfg.setTemplateLoader(templateLoader);; | |
cfg.setDefaultEncoding("UTF-8"); | |
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); | |
DataModel model = new DataModel(); | |
model.setName("Franz Wong"); | |
Template temp = cfg.getTemplate("main.ftl"); | |
Writer out = new OutputStreamWriter(System.out); | |
temp.process(model, out); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>com.franzwong.codepiece.java.freemarker</groupId> | |
<artifactId>freemarker001</artifactId> | |
<version>0.0.1-SNAPSHOT</version> | |
<dependencies> | |
<dependency> | |
<groupId>org.freemarker</groupId> | |
<artifactId>freemarker</artifactId> | |
<version>2.3.22</version> | |
</dependency> | |
</dependencies> | |
</project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Greet, ${name} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment