简体   繁体   中英

Java Spring MVC template Engine

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

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>

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM