In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
In this article Xiaobian introduces in detail "how to use Thymeleaf template in SpringBoot", the content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to use Thymeleaf template in SpringBoot" can help you solve your doubts.
one。 What is Thymeleaf?
Thymeleaf is a modern server-side Java template engine for Web and stand-alone environments, capable of handling HTML,XML,JavaScript,CSS and even plain text. The main goal of Thymeleaf is to provide an elegant and highly maintainable way to create templates. To this end, it is based on the concept of a natural template and injects its logic into the template file in a way that does not affect the template's use as a design prototype. This can improve design communication and narrow the gap between the design team and the development team. Thymeleaf is a HTML5 template engine that can be used for application development in Web environment. Thymeleaf provides an optional module for integrating Spring MVC. In application development, you can use Thymeleaf to completely replace JSP or other template engines, such as Velocity, FreeMarker, etc. The main goal of Thymeleaf is to provide a well-formed template creation method that can be displayed correctly by browsers. Thymeleaf template engine, instead of jsp.
Use Thymeleaf template 1.pom.xml in Spring Boot to add thymeleaf dependency org.springframework.boot spring-boot-starter-thymeleaf 2. Turn off thymeleaf caching
Add the following code under spring: in application.yml (to make the changed page take effect in time and achieve a similar hot deployment effect):
# enables the changed pages to take effect in a timely manner to achieve a similar hot deployment effect thymeleaf: cache: false
Note the indentation, indent after adding as follows:
3. Create a thymeleaf template page
Create a normal html file, hello.html, as follows:
Title
Add the namespace xmlns:th= "http://www.thymeleaf.org" to the tag of html to indicate that the page is a thymeleaf template page. That is, replace the above code with this so that you can use the th attribute in the tag on the page to extract the value in the model, similar to the EL expression. The specific usage code is as follows:
Title
Welcome to China, my name is, this year.
4. Create a class (for interacting with the above html page) ackage com.ysw.springboot01.controller;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.RequestMapping;@Controller@RequestMapping ("/ thy") public class ThymeleafController {@ RequestMapping ("/ hello") public String hello0 (Model model) {/ / store data model.addAttribute ("name", "Li Bai") into model Model.addAttribute ("age", "18"); / / Jump to hello.html template engine return "hello";}} 5. Access service path
The effect is as follows:
Read here, this "how to use Thymeleaf template in SpringBoot" article has been introduced, want to master the knowledge of this article also need to practice and use in order to understand, if you want to know more about the article, welcome to 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: 227
*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.