Created
September 13, 2020 12:34
-
-
Save koduki/7bf43c91e23b3d2ec0381f83ff4e88c3 to your computer and use it in GitHub Desktop.
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
@Path("/index.html") | |
@GET | |
@Produces(MediaType.TEXT_HTML) | |
public String goIndex() throws IOException, TemplateException, URISyntaxException { | |
return view("index.ftl", Map.of( | |
"hello", "Hello", | |
"world", "World" | |
)); | |
} | |
String view(String name, Map<String, String> model) throws TemplateException, IOException, URISyntaxException { | |
var config = new Configuration(Configuration.VERSION_2_3_23); | |
config.setDirectoryForTemplateLoading(new File(getClass().getResource("/WEB/").toURI())); | |
var out = new StringWriter(); | |
var template = config.getTemplate(name); | |
template.process(model, out); | |
out.flush(); | |
return out.toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment