In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Most people do not understand the knowledge points of this article "how to use Thymeleaf in SpringBoot", so the editor summarizes the following contents, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to use Thymeleaf in SpringBoot" article.
Preface
Thymeleaf is a modern server-side Java template engine for Web and stand-alone environments.
The main goal of Thymeleaf is to bring elegant natural templates to your development workflow-HTML that can be displayed correctly in browsers or can also be used as static prototypes to achieve stronger collaboration in the development team.
With Spring Framework modules, extensive integration with your favorite tools, and the ability to plug in your own features, Thymeleaf is an ideal choice for modern HTML5 JVM Web development.
How does Thymeleaf compare to other template engines such as Velocity or FreeMarker?
Velocity and FreeMarker are both great software, but they deal with template problems in a completely different way than Thymeleaf.
Thymeleaf places a strong emphasis on natural templating-- allowing templates to become working prototypes, while the other two templates don't-- and its syntax tries (arguably) to be cleaner and more in line with current web development trends. In addition, from an architectural point of view, Velocity and FreeMarker are sequential text processors, while Thymeleaf is based on tag parsing technology. This allows Thymeleaf to take advantage of interesting features specific to tag-based environments, especially web.
Steps for SpringBoot to use Thymeleaf
The first step is to introduce Thymeleaf starter dependency. The specific code is as follows:
Org.springframework.boot spring-boot-starter-thymeleaf
The second step is to add Thymeleaf-related configuration in application.properties, as shown below:
Server.port=8090server.servlet.context-path=/sbe# shuts down Thymeleaf cache development process does not need to restart spring.thymeleaf.cache = false# setting thymeleaf page encoding spring.thymeleaf.encoding=UTF-8spring.thymeleaf.mode=HTML5# setting thymeleaf page suffix spring.thymeleaf.suffix=.html# setting thymeleaf page storage path spring.thymeleaf.prefix=classpath:/templates/
The third step is to write a Controller to visit the Thymeleaf page.
@ Controller@RequestMapping ("/ hello") public class ThymeleafHelloWrodController {@ RequestMapping ("/ thymeleaf") public String helloThymeleaf (Model model) {model.addAttribute ("hello", "helloThymeleaf!") ; return "hello/index";}}
The Thymeleaf page code is as follows:
Insert title here hello
test
Enter the URL: http://localhost:8090/sbe/hello/thymeleaf of the Controller that accesses the Thymeleaf page in the browser to test. The test results are as follows:
The above is about the content of this article on "how to use Thymeleaf in SpringBoot". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.