只要使用thymeleaf,只需要导入依赖

        <!--thymeleaf模板,我们都基于3.x开发的-->
        <dependency>
            <groupId>org.thymeleaf</groupId>
            <artifactId>thymeleaf-spring5</artifactId>
        </dependency>
        <dependency>
            <groupId>org.thymeleaf.extras</groupId>
            <artifactId>thymeleaf-extras-java8time</artifactId>
        </dependency>

我们将html放在我们的thymeleaf下

按住Ctrl+n,弹出搜索框ThymeleafProperties(读源码)

html文件

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<!--xmlns:th="http://www.thymeleaf.org"增加約束-->
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<!--所有的html元素可以被thymeleaf替換接替:th:元素名-->
<div th:text="${msg}" ></div>
<!--th:text    文本替换-->
<!--${...}變量,用于字符串的替换或对象获取或属性绑定-->
<!--*{...}選擇表達式-->
<!--#{...}消息-->
<!--@{}的使用:用于获取链接地址。-->
</body>
</html>
Controller文件
package com.huang.controller;

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

@Controller
public class IndexController {
    @RequestMapping("/test")
    public String test(Model model){
        model.addAttribute("msg","hello,springboot");
        return "test";
    }
}

 

posted on 2022-05-01 01:12  阿霖找BUG  阅读(36)  评论(0)    收藏  举报