Spring boot uses thymeleaf as the basic step for the template, springthymeleaf
Preface
In the development process, it is necessary to use the template engine. Jsp is obviously unable to keep up with the development of the times. Is freemarker enough? Try thymeleaf.
Springboot officially recommends freemarker and thymeleaf. thymeleaf is more powerful than freemarker. It can dynamically replace static content in tags so that the front-end can write pages with peace of mind, in the background, you can renew the interface with peace of mind. You only need to replace the variables. I don't know whether VUE copied thymeleaf or thymeleaf copied VUE, but it doesn't matter, for the vast majority of code slaves, it is practical.
After reading the materials and configuring them, I will share the implementation process with you. I will not talk much about it below. Let's take a look at the detailed introduction.
1. Introduction of pom
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
Ii. Add thymeleaf configuration in application. properties
spring.thymeleaf.cache=falsespring.thymeleaf.check-template=truespring.thymeleaf.check-template-location=truespring.thymeleaf.content-type=text/htmlspring.thymeleaf.enabled=truespring.thymeleaf.encoding=utf-8spring.thymeleaf.mode=HTML5spring.thymeleaf.prefix=classpath:/templates/spring.thymeleaf.suffix=.html
3. Compile html
<! DOCTYPE html>
Si, test class
Package com. mos. easyboot. admin. controller; import org. springframework. stereotype. controller; import org. springframework. ui. model; import org. springframework. web. bind. annotation. requestMapping; @ Controller @ RequestMapping ("demo") public class DemoController {@ RequestMapping ("index") public String index (Model model) {String textValue = "Shi Wen Dao, only you can do it. Sergeant said, if there is nothing left, Corporal said, laughing. "+" Said without a smile. "+" There are some suggestions: If the Mingdao is ignorant, if the entrance is retired, if the Yi Dao is (lei), if the shangde is not good, if the guangde is insufficient, if the jiande is stolen, the quality is really RuO Yu; the generosity is not Yu; the big device is not Cheng; the big sound is Greek; the elephant is invisible. "+" Dao is unknown. "+" Fu weandao, good beginning and good. "; Model. addAttribute (" textValue ", textValue); return" demo/demo ";}}
Wu, page Effect
Land and Data Rendering
VUE has a problem with SSR (server-side rendering), although there are also solutions (see my previous article "separation of front and back ends Nuxt. js solves SEO problems), but I always feel that it is better to make the appropriate technology do business, and thymeleaf is equivalent to rendering on the server. view the page Source Code as follows:
Summary
The above is all the content of this article. I hope the content of this article has some reference and learning value for everyone's learning or work. If you have any questions, please leave a message to us, thank you for your support.