工具:主要加入时间
图片.png
1、基于“置顶-SpringBoot-最终整合”进行
2、SystemController控制器
package com.llhc.controller.admin;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.llhc.config.SiteConfig;
import com.llhc.model.Product;
/**
*
* 系统控制器
* @author 开发者
*
*/
@Controller
@RequestMapping("/system")
public class SystemController {
/**
*
* Thymeleaf+表达式
* @author 开发者
*
*/
@RequestMapping("thy1")
public String thy1(Model model){
String s = "<p style='color:red'>红色文字</p>";
Product p = new Product("实体");
boolean b = true;
List<Product> l = new ArrayList<>();
l.add(new Product("张三"));
l.add(new Product("离散"));
Date now = new Date();
model.addAttribute("host1",s);
model.addAttribute("host2",p);
model.addAttribute("host3",b);
model.addAttribute("host4",l);
model.addAttribute("host5",now);
return "hello";
}
}
3、修改test.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 date">
自定义格式化 ${#dates.format(host5,'yyyy-MM-dd HH:mm:ss')}:
<p th:text="${#dates.format(host5,'yyyy-MM-dd HH:mm:ss')}"></p>
</div>
</body>
</html>
网友评论