Spring JSP MVC 和 Thymeleaf MVC 的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41019274/
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
Difference between spring JSP MVC and Thymeleaf MVC
提问by Zafer Yilmaz
What is the difference between spring JSP MVC and Thymeleaf MVC? Which one is best way for spring web design ?
spring JSP MVC 和 Thymeleaf MVC 有什么区别?哪一种是春季网页设计的最佳方式?
采纳答案by Prometheus
Both of them are view layers of Spring MVC. Firstly, the very basic difference is the file extensions. (.jsp
& .html
)
它们都是 Spring MVC 的视图层。首先,最基本的区别是文件扩展名。( .jsp
& .html
)
Branislav in the comments is right, JSP
is not a template engine. It's compiled to the servlet and then the servlet is serving web content. On the other hand, Thymeleaf is a template engine which takes the HTML
file, parses it and then produces web content which is being served.
Branislav 中的评论是对的,JSP
不是模板引擎。它被编译到 servlet,然后 servlet 为 web 内容提供服务。另一方面,Thymeleaf 是一个模板引擎,它获取HTML
文件,解析它,然后生成正在提供的 Web 内容。
Thymeleaf is more like an HTML-ish view when you compare it with
JSP
views.We can use prototype code in thymeleaf : http://www.dineshonjava.com/2015/01/thymeleaf-vs-jsp-spring-mvc-view-layer.html#.WEkLzLKLTig
Since it is more HTML-ish code, thymeleaf codes are more readable (of course you can disrupt it and create unreadable codes, but at the end, it will be more readable when you compare it with
.jsp
files)Standard Dialect (The expression language) is much more powerful than JSP Expression Language
If we put all this to an edge, thymeleaf is the slow one here.
当您将 Thymeleaf 与
JSP
视图进行比较时,它更像是一个 HTML 风格的视图。我们可以在 thymeleaf 中使用原型代码:http: //www.dineshonjava.com/2015/01/thymeleaf-vs-jsp-spring-mvc-view-layer.html#.WEkLzLKLTig
由于它是更多的 HTML-ish 代码,因此 thymeleaf 代码更具可读性(当然你可以破坏它并创建不可读的代码,但最后,当你将它与
.jsp
文件进行比较时,它会更具可读性)标准方言(表达式语言)比 JSP 表达式语言强大得多
如果我们把这一切放在一边,百里香在这里是缓慢的。
I would suggest you to take a look at this doc : http://www.thymeleaf.org/doc/articles/thvsjsp.html
我建议你看看这个文档:http: //www.thymeleaf.org/doc/articles/thvsjsp.html
回答by Zildyan
Thymeleaf is template resolver that process template and produce pure html.
Thymeleaf 是处理模板并生成纯 html 的模板解析器。
Thymeleaf is way better in my opinion because it have good underlying priciples and exploits natural behaviour of browsers.
在我看来,Thymeleaf 更好,因为它具有良好的基本原理并利用浏览器的自然行为。
Jsp makes html hard to read, it becomes weird mixture of html and java code which makes a lot of problems in comunication between designer - developer.
Jsp 使得 html 难以阅读,它变成了 html 和 java 代码的奇怪混合,这在设计者 - 开发者之间的沟通中产生了很多问题。
Thymeleaf preserves html and only adds tags that are intuitive and very expressive. It enables you to work in offline mode and it works great with spring and I definitely recommend it above jsp.
Thymeleaf 保留了 html,只添加了直观且极具表现力的标签。它使您能够在离线模式下工作,并且它与 spring 一起工作得很好,我绝对推荐它高于 jsp。
http://www.dineshonjava.com/2015/01/thymeleaf-vs-jsp-spring-mvc-view-layer.html?m=1
http://www.dineshonjava.com/2015/01/thymeleaf-vs-jsp-spring-mvc-view-layer.html?m=1