In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to use SpringBoot+Thymeleaf based on HTML5 modern template engine". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use SpringBoot+Thymeleaf based on HTML5 modern template engine.
Start using
1. Introduce dependency
SpringBoot provides Starter for Thymeleaf by default, so you can simply introduce dependencies.
Org.springframework.boot spring-boot-starter-thymeleaf
Currently, the default version is 2.1, which can be modified if you want to upgrade the version to 3.0.
3.0.7.RELEASE 2.0.0
In order to facilitate development, the project case uses the hot deployment tool dev-tools, so that after we modify the page, IDEA will be loaded automatically, so as to achieve the effect of hot update.
Org.springframework.boot spring-boot-devtools runtime
Note: since IDEA turns off hot deployment by default, you need to make some settings for it to take effect. Solution: first press and hold Ctrl+Shift+Alt+/, then enter Registry, and then check compiler.automake.allow.when.app.running. In addition, Build- > Compiler should also be checked with Build Project automatically.
two。 Add related configuration
Thymeleaf turns page caching on by default, and caching should be turned off during development. In addition, we usually specify the storage path of the page. (default is classpath:/templates/)
The application.yml configuration is as follows: spring: thymeleaf: cache: false # turn off cache prefix: classpath:/views/ # add path prefix
3. Write HTML
Writing Thymeleaf is no different from writing HTML5 pages, the biggest change is to use extended attributes (th:xx) to interact with the server, retaining the original page style, which is also the preferred style of Thymeleaf. For example, in the following simple case, when we start the project, we find that the page jumps to a link to a short book, which also verifies Thymeleaf's excellent ability to cover native page data.
Page code:
Thymeleaf Welcome to Thymeleafe! Poke me with a surprise.
Backend code:
@ Controllerpublic class UserController {@ GetMapping ("/") public String index (Model model) {model.addAttribute ("info", "user/list"); return "index";} @ GetMapping ("/ user") public String hehe (Model model) {model.addAttribute ("user", new User (UUID.randomUUID (). ToString (), "yizhiwazi", "20170928")); return "user" } @ GetMapping ("/ user/list") public String userlist (Model model) {List userList = new ArrayList (); userList.add (new User (UUID.randomUUID (). ToString (), "yizhiwazi", "20170928")); userList.add (new User (UUID.randomUUID (). ToString (), "kumamon", "123456"); userList.add (new User (UUID.randomUUID (). ToString (), "admin", "admin") Model.addAttribute ("userList", userList); return "userList";}
Now let's try to backfill a form showing individual user information.
Next, let's move on to a more complex case, such as displaying a list of users and traversing a batch of users without writing new tags.
User list user name: login password: at this point, I believe you have a deeper understanding of "SpringBoot+Thymeleaf based on HTML5 modern template engine". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.