图片.png
1、基于“置顶-SpringBoot-最终整合”进行
2、控制器
package com.llhc.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.llhc.model.Product;
@Controller
@RequestMapping("/system")
public class TestThymeleafController {
/**
*
* Thymeleaf+表达式
* @author 开发者
*
*/
@RequestMapping("thy1")
public String thy1(Model model){
String s = "<p style='color:red'>红色文字</p>";
Product p = new Product("实体");
boolean b = true;
model.addAttribute("host1",s);
model.addAttribute("host2",p);
model.addAttribute("host3",b);
return "hello";
}
}
3、在resources下的templates文件夹,创建hello.html
<!DOCTYPE HTML>
<!-- 声明当前文件是Thymeleaf,可以用th开头 -->
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Thymeleaf</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" media="all" href="../../webapp/static/css/style.css" th:href="@{/static/css/style.css}"/>
<script type="text/javascript" src="../../webapp/static/js/thymeleaf.js" th:src="@{/static/js/thymeleaf.js}"></script>
<script>
testFunction();
</script>
<style>
h2{
text-decoration: underline;
font-size:0.9em;
color:gray;
}
</style>
</head>
<body>
<!-- 条件判断-->
<div class="showing">
<h2>条件判断</h2>
<p th:if="${host3}" >b是true,显示数据</p>
</div>
</body>
</html>
网友评论