Skip to content

Instantly share code, notes, and snippets.

@koduki
Created September 13, 2020 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koduki/7bf43c91e23b3d2ec0381f83ff4e88c3 to your computer and use it in GitHub Desktop.
Save koduki/7bf43c91e23b3d2ec0381f83ff4e88c3 to your computer and use it in GitHub Desktop.
@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