美文网首页
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-条件

  • Thymeleaf-包含

  • Thymeleaf-遍历

  • Thymeleaf-引入

  • Thymeleaf-内置工具

  • Thymeleaf-表达式

  • 无条件的条件

    当潮流爱新鲜 当旁人爱标签 幸的伴着你我 是窝心的自然 当闲言再尖酸 给他妒忌多点 因世上的至爱 是不计较条件 谁...

  • if 条件

    if条件 代码的缩进为一个tab键,一般都用tab 或者四个空格 在python 编程中 Tab 不要跟空格混着用...

  • 条件

    条 件 从来没想过,你我之间要有什么条件。 更没想过,有一天这个条件是由你提出来的。 你提出的条件,我当然全部都要...

  • 条件

    “先生,您好,我们是知名的教育机构,高薪聘请北美专业教师一对一授课,有着完善的线上学习与服务,可以有效提升少儿英语...

网友评论

      本文标题:Thymeleaf-条件

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