只要使用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"; } }
本文来自博客园,作者:阿霖找BUG,转载请注明原文链接:https://www.cnblogs.com/lin-07/articles/16212028.html
浙公网安备 33010602011771号