您好,登錄后才能下訂單哦!
這篇文章主要介紹“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模板的使用方法”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注億速云網站,小編會繼續努力為大家帶來更多實用的文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。