Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The relationship between SpringMVC and template engine

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains the relationship between SpringMVC and template engine. The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn the relationship between SpringMVC and template engine.

What is a template engine?

The template engine (in this case, the template engine for Web development) is generated to separate the user interface from the business data (content). It can generate documents in a specific format, and the template engine for the website will generate a standard document.

The basic mechanism of the template engine is to replace (transform), convert the specified tag into the required business data, and transform the output of the specified pseudo statement according to a certain process.

The relationship between SpringMVC and template engine

Flow chart of the request processed by SpringMVC:

The template engine works in steps 8, 9 and 10.

For a more detailed introduction of the principle, click me to jump.

Version support

Focus on Velocity, because it has not been updated for 6 consecutive years since 2010, and the version remains at 1.7. it has not been updated until the last two years, and the latest version is 2.1 updated in March 2019, but it has not changed much.

Spring official website original text: As of Spring Framework 4.3, Velocity support has been deprecated due to six years without active maintenance of the Apache Velocity project. We recommend Spring's FreeMarker support instead, or Thymeleaf which comes with Spring support itself.

Spring Framework 4.3 and SpringBoot 1.5 remove support for Velocity, so if you want to use it in subsequent versions, you need to introduce it manually.

Inheritance relationship of template

View parser used by JSP: InternalResourceViewResovler inherits UrlBasedViewResolver

Video parsers for Freemarker and Velocity: FreemarkerViewResolver and VelocityViewResolver, both of which inherit AbstractTemplateViewResolver

FreeMarker view parser inheritance relationship: Velocity view parser inheritance relationship:

Limitations of JSP

JSP can only run in a servlet container, there are no restrictions on other template engines, and other template engines are not only used for web development (JSP is also the fastest due to pre-compilation)

When SpringBoot starts with an embedded servlet container, there are some restrictions on JSP support:

When using tomcat or jetty, you need to use the war package. Executable jar cannot run JSP because the file mode is hard-coded in tomcat/jetty

Undertow does not support JSP

The custom error.jsp created cannot override the default error handling

Note when using JSP in docker: since java files and class files are generated after jsp rendering and stored on disk, if you use docker, you need to specify the temp directory in the environment variable

Comparison of back-end template engines

Learning difficulty: Thymeleaf < Velocity < JSP

Thymeleaf is closer to H6 grammar, modern template grammar.

Portability:

Thymeleaf: strong portability and Spring ecology

Velocity: strong portability, lack of surrounding ecology

JSP: must be a Servlet or JSP container

Performance:

Themeleaf: interpretation execution, poor performance (used in the background, preferably not in the foreground)

Velocity: interpretive execution with good performance (using a lot of reflection)

JSP: the best performance, because first translated into source code and then compiled and executed, excellent performance

Thank you for your reading, the above is the content of "the relationship between SpringMVC and template engine", after the study of this article, I believe you have a deeper understanding of the relationship between SpringMVC and template engine, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report