8

What template engine is in Spring, which is similar to Blade in laravel?

I am new to Spring, I searched templating engines, but have only found Jtwig, although it seems more a set of functions.

I need that like blade, to generate templates with the header, content, footer, include other views, etc. Thanks

Tieson T.
  • 20,774
  • 6
  • 77
  • 92

4 Answers4

8

Try Thymeleaf. It is supposed to be the successor of JSP (now considered outdated).

See this tutorial on how to integrate it with Spring. Even the Spring team themselves are endorsing Thymeleaf.

To see Thymleaf layouting in action, see this page.


Sneak peek

main.html

...
<div th:replace="fragments/footer :: footer">
    footer placeholder text to be replaced
</div>

fragments/footer.html

<!DOCTYPE html>
<html>
  <head>
    ...
  </head>
  <body>
    <div th:fragment="footer">
      actual footer text
    </div>
  </body>
</html>
Rey Libutan
  • 5,226
  • 9
  • 42
  • 73
3

There are a number of java templating engines that work well with spring: velocity, freemarker, thyme.

If it was me, I'd consider trimou. It's a java moustache implementation which uses {{}} syntax for variables and doesn't allow for client side logic (that might be a good thing).

This has become a very popular style of templating and might gain you the ability to share the same templates client and server side when building modern single page web applications.

Robert Moskal
  • 21,737
  • 8
  • 62
  • 86
  • Looks very interesting. More than Mustache, and CDI integration. Seems focused on performances. I will give it a try right now with Spring MVC. – Nicolas Zozol Nov 19 '15 at 08:36
3

You can try Apache Tiles. It's is a template composition framework. Tiles was originally built to simplify the development of web application user interfaces, it has seamless integration with Spring. Tiles allows authors to define page fragments which can be assembled into a complete page at runtime.

Spring Tiles integration

underdog
  • 4,447
  • 9
  • 44
  • 89
1

For me the equivalent is Thymeleaf...

You can integrate angular.js, angular, react.js etc if you want to implement a single page web app

Carlos Chávez
  • 422
  • 5
  • 14
  • i am using springboot+thymeleaf+AngularJs 1.6.9,is it possible to implement SPA ? – Vignesh R Apr 18 '18 at 05:38
  • Hello, i recommend you to follow this tutorial https://spring.io/guides/tutorials/spring-security-and-angular-js/ i do not recommend you to mix angularjs with thymeleaf for a SPA, angularjs works better alone – Carlos Chávez Apr 18 '18 at 13:58