溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

thymeleaf模板的使用方法

發(fā)布時(shí)間:2021-06-25 12:04:17 來(lái)源:億速云 閱讀:108 作者:chen 欄目:編程語(yǔ)言

這篇文章主要介紹“thymeleaf模板的使用方法”,在日常操作中,相信很多人在thymeleaf模板的使用方法問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”thymeleaf模板的使用方法”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!

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">銷(xiāo)售</a></li>
                <li><a href="/sale/toMainXsList">銷(xiāo)售查詢(xún)</a></li>
                <li><a href="/sale/toMainXsKc">庫(kù)存</a></li>
            </ul>
        </div>
        <!--    主內(nèi)容start-->
        <div id="section" th:include="::content">
            頁(yè)面正文內(nèi)容
        </div>
        <!--    主內(nèi)容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">
        銷(xiāo)售模塊
    </div>
</html>
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      th:replace="demo/layout1">
    <div th:fragment="content">
        銷(xiāo)售庫(kù)存
    </div>
</html>
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      th:replace="demo/layout1">
    <div th:fragment="content">
        銷(xiāo)售列表
        <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 銷(xiāo)售模塊
     * @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 銷(xiāo)售列表
     * @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 銷(xiāo)售庫(kù)存
     * @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";
    }

}

到此,關(guān)于“thymeleaf模板的使用方法”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注億速云網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI