简体   繁体   English

Java Spring MVC模板引擎

[英]Java Spring MVC template Engine

What template engine is in Spring, which is similar to Blade in laravel? Spring中有什么模板引擎,类似于laravel中的Blade?

I am new to Spring, I searched templating engines, but have only found Jtwig, although it seems more a set of functions. 我是Spring的新手,我搜索了模板引擎,但只发现了Jtwig,尽管它看起来像是一组函数。

I need that like blade, to generate templates with the header, content, footer, include other views, etc. Thanks 我需要像刀片一样的工具来生成带有页眉,内容,页脚,包括其他视图等的模板。谢谢

Try Thymeleaf . 尝试Thymeleaf It is supposed to be the successor of JSP (now considered outdated). 它应该是JSP的后继产品(现在已经过时了)。

See this tutorial on how to integrate it with Spring. 请参阅教程,了解如何将其与Spring集成。 Even the Spring team themselves are endorsing Thymeleaf . 甚至春季团队本身也认可Thymeleaf

To see Thymleaf layouting in action, see this page . 要查看实际的Thymleaf布局,请参阅此页面


Sneak peek 抢先看

main.html main.html

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

fragments/footer.html fragment / 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. 有许多Java模板引擎可以很好地与spring配合使用:速度,freemarker和百里香。

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). 这是一个Java小胡子实现,它对变量使用{{}}语法,并且不允许客户端逻辑(这可能是一件好事)。

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. 这已成为一种非常流行的模板样式,并且可能使您能够在构建现代的单页Web应用程序时共享客户端和服务器端相同的模板。

You can try Apache Tiles . 您可以尝试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最初是为了简化Web应用程序用户界面的开发而构建的,它与Spring无缝集成。 Tiles allows authors to define page fragments which can be assembled into a complete page at runtime. Tiles允许作者​​定义页面片段,这些片段可以在运行时组合成一个完整的页面。

Spring Tiles integration Spring Tiles集成

For me the equivalent is Thymeleaf... 对我而言,相当于Thymeleaf ...

You can integrate angular.js, angular, react.js etc if you want to implement a single page web app 如果要实现单页Web应用程序,则可以集成angular.js,angular,react.js等

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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