springboot(6)-how to customize the homepage, template engine Thymeleaf

1 How to customize the homepage

Source code shows the execution process
Insert picture description here
Insert picture description here

2 template engine

https://docs.spring.io/spring-boot/docs/2.1.6.RELEASE/reference/htmlsingle/#using-boot
import dependencies in pom.xml
We are all developed by version 3.x

	<dependency>
			<groupId>org.thymeleaf</groupId>
			<artifactId>thymeleaf-spring5</artifactId>
		</dependency>
		<dependency>
			<groupId>org.thymeleaf.extras</groupId>
			<artifactId>thymeleaf-extras-java8time</artifactId>
		</dependency>

A test
Insert picture description here
as long as you need to use it, you thymeleafonly need to import the corresponding dependencies! We will put the html file to our templates
Insert picture description here
test
Insert picture description herein whichTestController.java

package com.zs.helloword.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

// 在templates目录下的页面 只能通过controller来跳转
// 需要模板引擎的支持 thymeleaf
@Controller // 跳到一个页面
public class TestController {
    
    
    @RequestMapping("/test")
    public String test(Model model) {
    
    
        model.addAttribute("msg","hello,springboot!");
        return "test";
    }
}

Test th:text th:utext
Insert picture description here
testth:each
Insert picture description here

Guess you like

Origin blog.csdn.net/zs18753479279/article/details/112510346