1. 使用maven构建SpringBoot的名叫spring-boot-view-thymeleaf-if-switch项目

2. pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.bjbs</groupId><artifactId>spring-boot-view-thymeleaf-if-switch</artifactId><version>0.0.1-SNAPSHOT</version><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.13.RELEASE</version></parent><!-- 修改jdk版本 --><properties><java.version>1.8</java.version><!-- 指定thymeleaf和thymeleaf-layout-dialect高版本可以防止html标签不规范报错 --><thymeleaf.version>3.0.2.RELEASE</thymeleaf.version><thymeleaf-layout-dialect.version>2.0.4</thymeleaf-layout-dialect.version></properties><dependencies><!-- springBoot的启动器 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId></dependency></dependencies>
</project>

3. 在src/main/resources/templates下新建condition.html

<!DOCTYPE html>
<html><head><meta charset="UTF-8" /><title>Thymeleaf条件判断</title></head><body><h3>Thymeleaf if条件判断</h3><span th:if="${sex} == '男'">性别: 男</span><span th:if="${sex} == '女'">性别: 女</span><hr/><h3>Thymeleaf switch条件判断</h3><div th:switch="${id}"><span th:case="1">ID为1</span><span th:case="2">ID为2</span><span th:case="3">ID为3</span></div></body>
</html>

4. 新建UserController.java

package com.bjbs.controller;import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;@Controller
public class UserController {@RequestMapping("/condition")public String condition(Model model) {model.addAttribute("sex", "女");model.addAttribute("id", "1");return "condition";}
}

5. 新建App.java

package com.bjbs;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;/*** SpringBoot启动类*/
@SpringBootApplication
public class App {public static void main(String[] args) {SpringApplication.run(App.class, args);}
}

6. 启动项目, 并使用浏览器访问

012_SpringBoot视图层技术thymeleaf-条件判断相关推荐

  1. SpringBoot中使用Thymeleaf常用功能(二):测试Thymeleaf条件判断

    环境搭建请先阅读文章一 在一的基础上 先在index.html中添加超链接 <a th:href="@{iftest}">测试条件判断</a> 在Thyme ...

  2. 010_SpringBoot视图层技术thymeleaf-变量输出与字符串操作

    一. Thymeleaf变量输出 1. th:text在页面中输出变量. 2. th:value将变量输出到input标签的value中. 二. Thymeleaf字符串操作 1. Thymeleaf ...

  3. 015_SpringBoot视图层技术thymeleaf-URL表达式

    1. url表达式: th:href和th:src. 2. url表达式基本语法: @{}. 3. 绝对路径: <a th:href="@{http://www.baidu.com}& ...

  4. 014_SpringBoot视图层技术thymeleaf-访问域对象

    1. 使用maven构建SpringBoot的名叫spring-boot-view-thymeleaf-scope项目 2. pom.xml <project xmlns="http: ...

  5. 013_SpringBoot视图层技术thymeleaf-迭代遍历

    1. 使用maven构建SpringBoot的名叫spring-boot-view-thymeleaf-each项目 2. pom.xml <project xmlns="http:/ ...

  6. 011_SpringBoot视图层技术thymeleaf-日期格式化

    一. 日期格式化 1. ${#dates.format(birthday)}格式化日期, 默认的以浏览器默认语言为格式化标准. 2. ${#dates.format(birthday,'yyy/MM/ ...

  7. 008_SpringBoot视图层技术jsp

    1. 使用maven构建SpringBoot的名叫spring-boot-view-jsp项目 2. pom.xml <project xmlns="http://maven.apac ...

  8. THYMELEAF 如何用TH:IF做条件判断

    TestController 增加一个布尔值数据,并且放在model中便于视图上获取 package com.how2java.springboot.web; import java.util.Arr ...

  9. Thymeleaf th:each 循环迭代与 th:if、th:switch 条件判断

    文章目录 th:each 循环迭代 循环基本用法 获取迭代状态 条件判断 th:if th:unless th:switch th:each 循环迭代 循环基本用法 1.对于信息页面,数据格式是一样时 ...

最新文章

  1. 计算机软件属于输入还是输出,计算机基本输入输出系统是什么意思(基本输入输出系统简介)...
  2. 【alibaba-cloud】nacos详解
  3. [线性代数]Note 1--方程组的几何解释
  4. 10kv线路负载率计算_电工必懂计算公式,你若不会,如何立足于电力行业?
  5. Material Design之AppBarLayout总结
  6. JEECG(J2EE Code Generation) 基于代码生成器J2EE智能开发框架 杂记:发布新版本 JEECG_v2.0
  7. 将截断字符串或二进制数据。
  8. TCP粘包和拆包的定义,产生的原因以及解决方案
  9. 解决IDEA创建多模块项目找不到创建class类的问题
  10. oracle 除重更新,oracle数据库11.2.0.3升级到11.2.0.4
  11. caffe调参经验资料文章
  12. 企业——Redis的高可用的搭建
  13. php引用()详解及注意事项
  14. 【iOS逆向与安全程序员简历如何写?】四点忌讳以及过个要点:强调效果胜过强调水平、保持一致性和向上的趋势、在简历中要用好主题词。通常不超过两页(A4纸正反两面)为佳。
  15. Linux命令详解之 cat
  16. 软件测试常问面试题,你真的会搭建测试环境吗?
  17. G. 打印 LOGO(递归)
  18. Vagrant + VMBox 踩坑记录
  19. 微软Project Online落地中国
  20. STM32F407使用SPI读写SD TF卡(不能读取 会卡死)

热门文章

  1. ES6新特性5:类(Class)和继承(Extends)
  2. Grid_Oracle Grid Infrastructure概念介绍(概念)
  3. 作坊的反思-----走出软件作坊:三五个人十来条枪 如何成为开发正规军(四十)...
  4. 原生JavaScript实战之搜索框筛选功能
  5. Linux定时任务案例
  6. 【编程语言】Java基础进阶——面向对象部分
  7. CSS3实现带阴影的弹球
  8. 使用代理网络配置maven,显示导入失败的原因
  9. CenterWindow()的用法
  10. 注意scrapy中SgmlLinkExtractor的默认deny_extensions