The {@code "profile.ftl"} or {@code "profile.mustache"} is the path of the template relative to the class name. Ifthis class was {@code com.example.application.PersonView}, Freemarker or Mustache would then look for the file {@code src/main/resources/com/example/application/profile.ftl} or {@code src/main/resources/com/example/application/profile.mustache} respectively. If the template pathstarts with a slash (e.g., {@code "/hello.ftl"} or {@code "/hello.mustache"}), Freemarker or Mustache will look for the file {@code src/main/resources/hello.ftl} or {@code src/main/resources/hello.mustache} respectively.
A resource method with a view would looks something like this:
\@GET public PersonView getPerson(\@PathParam("id") String id) { return new PersonView(dao.find(id)); }
Freemarker templates look something like this:
{@code <#-- @ftlvariable name="" type="com.example.application.PersonView" --> }Hello, $ person.name?html}!
}
In this template, {@code} $person.name}} calls {@code getPerson().getName()}, and the {@code ?html} escapes all HTML control characters in the result. The {@code ftlvariable} commentat the top indicate to Freemarker (and your IDE) that the root object is a {@code Person}, allowing for better typesafety in your templates.
@see FreeMarker ManualMustache templates look something like this:
{@code }Hello, {person.name}}!
}
In this template, {@code} {person.name}}} calls {@code getPerson().getName()}.
@see Mustache Manual
|
|
|
|
|
|