Build HTML using TagCreator
masterYou can generate typesafe HTML by importing j2html.TagCreator.* statically. Use the tag methods (like body, h1, img) to compose your HTML structure. For elements that require attributes, use the .with[AttributeName]() pattern. Finally, call .render() to produce the HTML string.
import static j2html.TagCreator.*;
public class Main {
public static void main(String[] args) {
body(
h1("Hello, World!"),
img().withSrc("/img/hello.png")
).render();
}
}