Get the App
SLTechnology News&Howtos  ›  Development  › 

How SpringBoot uses thymeleaf templates

Shulou Source: shulou.com Published: 2022-06-03 11:00:17 09月22日 Update

This article mainly shows you "SpringBoot how to use the thymeleaf template", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "SpringBoot how to use the thymeleaf template" this article.

1. Import dependency

Org.springframework.boot spring-boot-starter-thymeleaf

New thymeleaf configuration in 2.application.yml file

# configure thymeleafspring: thymeleaf: cache: false

3. Create an entity class

Public class Student {private Integer stu_id; private String stu_name; public Integer getStu_id () {return stu_id;} public void setStu_id (Integer stu_id) {this.stu_id = stu_id;} public Student (Integer stu_id, String stu_name) {this.stu_id = stu_id; this.stu_name = stu_name;} public String getStu_name () {return stu_name } public void setStu_name (String stu_name) {this.stu_name = stu_name;}}

4. Create a templates folder under the src/main/resource folder

And create an index.html for later use

5. Create a ThyController class

@ Controller@RequestMapping ("/ thyController") public class ThyController {@ RequestMapping ("/ thymeleaf") public String thymeleaf (Model model) {List list=new ArrayList (); Student stu1=new Student (1, "Zhang San"); Student stu2=new Student (2, "Li Si"); Student stu3=new Student (3, Wang Wu); list.add (stu1); list.add (stu2); list.add (stu3); model.addAttribute ("stuList", list); return "index";}}

6.hello.html page

Ss

7. Browser testing

The above is all the content of the article "how SpringBoot uses thymeleaf templates". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Templates content documents articles folders learning help configuration entities understandability more organization browsers knowledge editing industry information information channels pages channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux vpn Shulou Tech Info Huawei Apple