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

How to use thymeleaf as a template for springboot

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly explains "how springboot uses thymeleaf as a template". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian slowly and deeply to study and learn "how springboot uses thymeleaf as a template" together!

Jsp has obviously not kept up with the development of the times. Is freemarker used enough? Try thymeleaf instead. Springboot officially recommends freemarker and thymeleaf, and thymeleaf is more powerful than freemarker, it can dynamically replace the static content in the tag, so that the front end can write pages, the background can be peace of mind, just need to replace the variables, this idea, do not know whether VUE copied thymeleaf or thymeleaf copied VUE, but it does not matter, for our majority of code slaves, practical is good

01

POM introduction

org.springframework.boot

spring-boot-starter-thymeleaf

02

application.properties Add thymeleaf configuration

spring.thymeleaf.cache=false

spring.thymeleaf.check-template=true

spring.thymeleaf.check-template-location=true

spring.thymeleaf.content-type=text/html

spring.thymeleaf.enabled=true

spring.thymeleaf.encoding=utf-8

spring.thymeleaf.mode=HTML5

spring.thymeleaf.prefix=classpath:/templates/

spring.thymeleaf.suffix=.html

03

write html

demo

This is the first paragraph.

This is the second paragraph.

04

test class

@RequestMapping("index")

public String index(Model model){

String textValue = "Sergeant heard the Tao, only can do it; Sergeant heard the Tao, if alive; Corporal heard the Tao, laugh." " +

"Not laughing is not enough. " +

"Therefore, there are suggestions: if the way is clear, if it is ignorant; if it is advanced, if it is retreated; if it is barbarians, if it is lei; if it is virtuous, if it is valley, if it is white, if it is humiliated, if it is not virtuous, if it is virtuous, if it is stolen, if it is true; if it is generous, there is no corner; if it is big, it will not be formed; if it is loud, it will not be loud; if it is invisible, it will be invisible. " +

"Dao Yin nameless. " +

"Only Tao, good beginning and good completion. ";

model.addAttribute("textValue",textValue);

return "demo/demo";

}

05

page effect

6

VUE has a SSR (server-side rendering) problem, although there are solutions (see my previous article "front-end separation Nuxt.js to solve SEO problems"), but always feel that it is better to let the appropriate technology do the business at the time, and thymeleaf is equivalent to rendering on the server side, view the page source code as follows:

Thank you for reading, the above is "springboot how to use thymeleaf as a template" content, after the study of this article, I believe we have a deeper understanding of how springboot uses thymeleaf as a template, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

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