Java Spring MVC 模板引擎
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31467737/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java Spring MVC template Engine
提问by Jonathan Cordero Duarte
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
我需要像刀片一样生成带有页眉、内容、页脚、包括其他视图等的模板。谢谢
回答by Incognito
Try Thymeleaf. It is supposed to be the successor of JSP
(now considered outdated).
试试百里香。它应该是JSP
(现在被认为已经过时)的继承者。
See thistutorial on how to integrate it with Spring. Even the Spring team themselves are endorsing Thymeleaf.
请参阅本教程,了解如何将其与 Spring 集成。甚至 Spring 团队自己也支持 Thymeleaf。
To see Thymleaf layouting in action, see this page.
要查看 Thymleaf 布局的实际效果,请参阅此页面。
Sneak peek
抢先看
main.html
主文件
...
<div th:replace="fragments/footer :: footer">
footer placeholder text to be replaced
</div>
fragments/footer.html
片段/页脚.html
<!DOCTYPE html>
<html>
<head>
...
</head>
<body>
<div th:fragment="footer">
actual footer text
</div>
</body>
</html>
回答by Robert Moskal
There are a number of java templating engines that work well with spring: velocity, freemarker, thyme.
有许多 java 模板引擎可以很好地与 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).
如果是我,我会考虑trimou。这是一个 java mustache 实现,它对变量使用 {{}} 语法并且不允许客户端逻辑(这可能是一件好事)。
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 应用程序时共享相同的模板客户端和服务器端。
回答by underdog
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.
你可以试试Apache Tiles。它是一个模板组合框架。Tiles 最初是为了简化 Web 应用程序用户界面的开发而构建的,它与 Spring 无缝集成。Tiles 允许作者定义可以在运行时组装成完整页面的页面片段。
回答by Carlos Chávez
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 等