天天看點

Thymeleaf初探

Thymeleaf初探

  • ​​Overview - 寫在前面​​
  • ​​Natural templates - 自然模闆​​
  • ​​Integrations galore - 內建豐富​​

Overview - 寫在前面

Thymeleaf is a modern server-side Java template engine for both web and standalone environments.

Thymeleaf’s main goal is to bring elegant natural templates to your development workflow — HTML that can be correctly displayed in browsers and also work as static prototypes, allowing for stronger collaboration in development teams.

With modules for Spring Framework, a host of integrations with your favourite tools, and the ability to plug in your own functionality, Thymeleaf is ideal for modern-day HTML5 JVM web development — although there is much more it can do.

Thymeleaf是适用于Web和獨立環境的現代伺服器端Java模闆引擎。

Thymeleaf的主要目标是為您的開發工作流程帶來優雅的自然模闆 -HTML可以在浏覽器中正确顯示,也可以作為靜态原型工作,進而可以在開發團隊中加強協作。

Thymeleaf擁有适用于Spring Framework的子產品,與您喜歡的工具的大量內建以及插入您自己的功能的能力,對于現代HTML5 JVM Web開發而言,Thymeleaf是理想的選擇-盡管它還有很多工作要做。

Natural templates - 自然模闆

HTML templates written in Thymeleaf still look and work like HTML, letting the actual templates that are run in your application keep working as useful design artifacts.

用Thymeleaf編寫的HTML模闆在外觀和功能上仍然類似于HTML,進而使應用程式中運作的實際模闆可以用作有用的設計工件。

<table>
  <thead>
    <tr>
      <th th:text="#{msgs.headers.name}">Name</th>
      <th th:text="#{msgs.headers.price}">Price</th>
    </tr>
  </thead>
  <tbody>
    <tr th:each="prod: ${allProducts}">
      <td th:text="${prod.name}">Oranges</td>
      <td th:text="${#numbers.formatDecimal(prod.price, 1, 2)}">0.99</td>
    </tr>
  </tbody>
</table>      

Integrations galore - 內建豐富

Eclipse, IntelliJ IDEA, Spring, Play, even the up-and-coming Model-View-Controller API for Java EE 8. Write Thymeleaf in your favourite tools, using your favourite web-development framework.

Check out our Ecosystem to see more integrations, including community-written plugins to speed-up your development with Thymeleaf.

Eclipse,IntelliJ IDEA,Spring,Play甚至是新興的Java EE Model-View-Controller API。8,使用您喜歡的Web開發架構在您喜歡的工具中編寫Thymeleaf。

繼續閱讀