这篇文章主要介绍“thymeleaf模板的使用方法”,在日常操作中,相信很多人在thymeleaf模板的使用方法问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”thymeleaf模板的使用方法”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="shortcut icon" href="../static/favicon.ico" th:href="@{/static/favicon.ico}"/>
</head>
<body>
<span th:text="${pageFlag}"></span>
<div class="con">
<div id="header">
<h2>City Gallery</h2>
<h3>欢迎,<span th:text="${session.userInfo.username}">xx</span>登录,<a href="/users/logout">退出登录</a></h3>
</div>
<div class="center">
<div id="nav">
<ul>
<li><a href="/sale/toMainXs">销售</a></li>
<li><a href="/sale/toMainXsList">销售查询</a></li>
<li><a href="/sale/toMainXsKc">库存</a></li>
</ul>
</div>
<!-- 主内容start-->
<div id="section" th:include="::content">
页面正文内容
</div>
<!-- 主内容end-->
</div>
<div id="footer">
@copy; sunpin.com
</div>
</div>
<style>
#header {
background-color:black;
color:white;
/*text-align:center;*/
padding:5px;
}
.center{
display: flex;
}
#nav {
line-height:30px;
background-color:#eeeeee;
/*height:300px;*/
width:20%;
padding:5px;
}
#section {
padding:10px;
background: red;
flex: 1;
}
#footer {
background-color:black;
color:white;
clear:both;
text-align:center;
padding:5px;
}
ul{
list-style: none;
}
</style>
</body>
</html><!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
th:replace="demo/layout1">
<div th:fragment="content">
销售模块
</div>
</html>
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
th:replace="demo/layout1">
<div th:fragment="content">
销售库存
</div>
</html>
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
th:replace="demo/layout1">
<div th:fragment="content">
销售列表
<span th:text="${saleList}">xx</span>
<table>
<tr th:each="sale : ${saleList}">
<th scope="row" th:text="${saleStat.index + 1}">1</th>
<td th:text="${sale.id}">neo</td>
<td th:text="${sale.price}">Otto</td>
<td th:text="${sale.quantity}">6</td>
<td th:text="${sale.totalprice}">6</td>
<td th:text="${sale.saledate}">6</td>
<td th:text="${sale.userid}">6</td>
<td th:text="${sale.productid}">6</td>
<td><a th:href="@{/toSaleEdit(id=${sale.id})}">edit</a>|<a th:href="@{/deleteSale(id=${sale.id})}">delete</a></td>
</tr>
</table>
</div>
</html>package com.example.springboot_jxc_0511.jxc.controller;
import com.example.springboot_jxc_0511.jxc.entity.Sale;
import com.example.springboot_jxc_0511.jxc.entity.Users;
import com.example.springboot_jxc_0511.jxc.service.ISaleService;
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 org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* <p>
* 前端控制器
* </p>
*
* @author gongxl
* @since 2021-05-11
*/
@Controller
@RequestMapping("/sale")
public class SaleController {
@Autowired
private ISaleService iSaleService;
/**
* @Author GongXl
* @Description 销售模块
* @Date 2021/5/11 16:59
* @Param [model]
* @return java.lang.String
**/
@RequestMapping("/toMainXs")
public String toMainXs(Model model) {
model.addAttribute("users",new Users());
model.addAttribute("pageFlag","xs");
return "main_xs";
}
/**
* @Author GongXl
* @Description 销售列表
* @Date 2021/5/11 16:59
* @Param [model]
* @return java.lang.String
**/
@RequestMapping("/toMainXsList")
public String toMainXsList(Model model) {
List<Sale> saleList = iSaleService.list();
model.addAttribute("users",new Users());
model.addAttribute("pageFlag","xs_list");
model.addAttribute("saleList",saleList);
return "main_xs_list";
}
/**
* @Author GongXl
* @Description 销售库存
* @Date 2021/5/11 16:59
* @Param [model]
* @return java.lang.String
**/
@RequestMapping("/toMainXsKc")
public String toMainXsKc(Model model) {
model.addAttribute("users",new Users());
model.addAttribute("pageFlag","xs_kc");
return "main_xs_kc";
}
}到此,关于“thymeleaf模板的使用方法”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注天达云网站,小编会继续努力为大家带来更多实用的文章!