美文网首页
Thymeleaf-条件

Thymeleaf-条件

作者: 通灵路耳 | 来源:发表于2020-03-07 16:59 被阅读0次
    图片.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>
    

    相关文章

      网友评论

          本文标题:Thymeleaf-条件

          本文链接:https://www.haomeiwen.com/subject/mfocdhtx.html