html5 builde,Fast and fluent Java HTML5 builder

Getting started with j2html

Import TagCreator to get started. j2html's syntax is fluent and closely matched to HTML:import static j2html.TagCreator.*;

public class Main {

public static void main(String[] args) {

body(

h1("Hello, World!"),

img().withSrc("/img/hello.png")

).render();

}

}

The Java code above becomes the HTML below:

Hello, World!

hello.png

Check out some more examples.

Intended use

Consider using j2html if:You love type safety. You love catching errors at compile time instead of waiting for some poor user to notice that something is wrong

You like to dynamically reuse your view code

You think template engines are too slow. This index page was rendered 100 000 times in less than a second on an i5-4670. That's about a thousand times faster than Apache 'Velocity' (hah!)

Be careful about using j2html if:You don't know Java and HTML well

You're creating a classic "website" that has a lot of static HTML (if it's all generated then it's fine)

Your application has a lot of text and you don't use language files / a database (string concatenation would get very annoying)

You use a CSS framework which relies on a lot of copy pasting HTML from docs. You'll have to translate these snippets to j2html

Why did you make this library?

First: j2html is a Java HTML builder. It's not a template engine, and it doesn't want to compete with template engines. We were looking for a good way to create HTML for a complex login solution which had many different forms (with different configurations, depending on user state and user actions, etc.), but very little actual HTML per page. The result was j2html. We decided to release the Java HTML builder we made, since it seems better than all the other Java HTML builders we found while researching the subject. Hopefully someone will find it useful!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值