Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 501
Jonathan Cordero Duarte Avatar asked Jul 17 '15 02:07

Jonathan Cordero Duarte


People also ask

What template engine does spring boot use?

1. JMustache is a template engine which can be easily integrated into a Spring Boot application by using the spring-boot-starter-mustache dependency. Pebble contains support for Spring and Spring Boot within its libraries.

What is a Java template engine?

Apache FreeMarker™ is a template engine: a Java library to generate text output (HTML web pages, e-mails, configuration files, source code, etc.) based on templates and changing data.

Is JSP a template engine?

Spring MVC, Struts or Apache Wicket are examples of web frameworks, whereas JSP, Velocity or FreeMarker are examples of template engines.


1 Answers

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>
like image 71
Rey Libutan Avatar answered Nov 02 '22 23:11

Rey Libutan