百里香叶是一种什么样的解决方案? [英] What kind of a solution is thymeleaf?

查看:78
本文介绍了百里香叶是一种什么样的解决方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读到如今,百里香叶比JSP更受欢迎. thymeleaf解决了JSP无法解决的哪个问题?与其他模板引擎相比,百里香叶怎么样?

I read that thymeleaf is preferred instead of JSP nowadays. Which problem does thymeleaf solve that JSP can't? How is thymeleaf compared to other templating engines?

推荐答案

好吧,这确实是一个基于意见的问题,这将是我的答案:)

Well, this is really an opinion-based question and such will be my answer :)

主要区别在于JSP被编译为Java servlet类,而Thymeleaf读取模板文件,解析其DOM,然后对其应用模型.即使启用了Thymeleaf的模板缓存,这也会带来性能开销,并给JSP提供性能优势.另一方面,它使Thymeleaf的开发更加容易,这就是原因:

The main difference is that JSPs are compiled to Java servlet classes whereas Thymeleaf reads the template file, parses its DOM and then applies the model to it. This introduces a performance overhead and gives JSPs a performance edge, even with Thymeleaf's template caching enabled. On the other hand, it makes Thymeleaf much easier to develop with and here's why:

  • Thymeleaf使用纯HTML作为模板.您可以选择具有data-th属性的纯HTML5方法,也可以选择原始的自定义命名空间th:属性.使用纯HTML的好处是可以在浏览器中打开它,这使设计人员可以更轻松地完成工作:设计人员和开发人员都可以在同一个文件上工作.

  • Thymeleaf uses plain HTML as its templates. You can either choose a pure HTML5 approach with data-th attributes or the original custom-namespace th: attributes. The benefit of using plain HTML is that you can open it in a browser, which makes it easier for the designers to do their work: both the designers and developers can work on the same file.

Thymeleaf模板可以在没有应用程序服务器的情况下使用,并且还可以与嵌入式服务器很好地配合使用.您不必跳过所有步骤即可对模板进行集成测试,您可以通过 Thymeleaf自己的模板进行集成测试独立模板测试库或作为功能测试的一部分,例如您的Spring MVC控制器的集成测试.

Thymeleaf templates can be used without an application server and they also work nicely with embedded servers. You don't have to jump through hoops to do integration testing of your templates, which you can do either through Thymeleaf's own standalone template testing library or as a part of functional tests, e.g. integration tests of your Spring MVC controllers.

Thymeleaf具有更轻量,更强大的语法,并与Spring生态系统更好地集成.它的设计目的是从概念上与Spring集成,但是您也可以在Spring之外使用它.我发现它对于电子邮件和报告生成很有用.

Thymeleaf has more lightweight and more powerful syntax and better integration with Spring ecosystem. It was designed to integrate with Spring from its conception, but you can also use it outside of Spring. I found it useful for email and report generation.

胸腺模板允许大量重用;您可以创建小的模板片段,然后在其他模板中重用它们,这在具有许多模板的项目中是一个救命稻草.尽管您还可以找到

Thymeleaf templates allow for great reuse; you can create small template fragments and reuse them in other templates, which is a lifesaver in projects with lots of templates. It also has great layout support out of the box although you can also find community plugins if you need more flexibility/power.

免责声明:一年多来我没有做过Thymeleaf的任何开发,但据我所知,它并没有太大改变.您还可以查看 Spring上的这篇文章-虽然有些陈旧,但确实说明了主要区别.

Disclaimer: I haven't done any Thymeleaf development in over a year but from what I can see, it hasn't changed that much. You can also take a look at this article from Spring - while it is a bit old, it does illustrate the main differences.

这篇关于百里香叶是一种什么样的解决方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆