SpringBoot入门——Thymeleaf简单使用
本文只展示代码实现,具体参考此博客实现
举例使用Thymeleaf的:赋值,拼接,if判断,unless判断,for 循环,HTML文本替换
IndexController后台代码
@Controller
public class IndexController {/**** index页面*/@RequestMapping("/Index")public ModelAndView Index(){/*for循环*/List<UserModel> users= new ArrayList<>();UserModel um=new UserModel();um.setAge("18");um.setName("Howie");UserModel um1=new UserModel();um1.setAge("20");um1.setName("Tang");users.add(um);users.add(um1);Map<String, Object> map=new HashMap<>();/*赋值*/map.put("description","Hello SpringBoot");/*拼接*/map.put("joint","Howie");/*for循环*/map.put("users", users);/*if unless判断*/map.put("test", "123");/*HTML文本替换*/map.put("HTML", "<h1>Hello</h1>");return new ModelAndView("index","result",map);}
}
index页面代码
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body><h1>Hello Index</h1><h2>赋值</h2><p th:text="${result.description}">description</p><h2>拼接</h2><span th:text="'Welcome,' + ${result.joint} + '!'"></span><h2>for循环</h2><span th:each="nn: ${result.users}">年龄:<span th:text="${nn.age}"></span>姓名:<span th:text="${nn.name}"></span><br></span><h2>if判断</h2><a href="www.baidu.com " th:if="${result.test =='123'}" ></i>百度</a><a href="www.taobao.com " th:if="${result.test =='1234'}" ></i>淘宝</a><br><h2>unless判断</h2><a href="www.baidu.com " th:Unless="${result.test =='123'}" ></i>百度</a><a href="www.taobao.com " th:Unless="${result.test =='1234'}" ></i>淘宝</a><br><h2>HTML文本替换</h2><span th:utext="${result.HTML}"></span></body>
</html>
Usermodel自定义
public class UserModel {public String name;public String age;public String getName() {return name;}public void setName(String name) {this.name = name;}public String getAge() {return age;}public void setAge(String age) {this.age = age;}
运行页面效果
SpringBoot入门——Thymeleaf简单使用相关推荐
- SpringBoot入门之简单配置
今天下载了<JavaEE开发的颠覆者SpringBoot实战>这本书,发现Spring还有好多遗漏的部分,算是又恶补了一下,今天主要是学习下SpringBoot的配置. 一.基本配置 1. ...
- thymeleaf select_SpringBoot整合thymeleaf简单的CRUD
SpringBoot整合thymeleaf简单的CRUD 最近发现之前学习的东西好多都忘记了,这里开始每天记录一点之前学习过的东西,今天就从最简单的CRUD开始吧. 一.老规矩还是先看看相应的目录结构 ...
- springboot 入门教程(4)--web开发(spring mvc和Thymeleaf模板,带源码)
2019独角兽企业重金招聘Python工程师标准>>> 首先回顾下前几篇的内容:springboot 入门教程(1),springboot 入门教程-Thymeleaf(2), sp ...
- 玩转springboot:thymeleaf模板引擎入门程序
一.前言 常用的模板引擎有:JSP.Velocity.Freemarker.Thymeleaf 但是,Springboot默认是不支持JSP的,默认使用thymeleaf模板引擎.而且,语法更简单,功 ...
- springboot之thymeleaf入门
springboot之thymeleaf入门 由于JSP是不能在压缩包内解析的,所以spring boot默认不支持JSP的.因此我们需要使用第三方的模板引擎,比如我们这次介绍的thymeleaf 官 ...
- 最简单最详细的SpringBoot入门项目——HelloWorld
最详细的SpringBoot入门项目--HelloWorld 关于SpringBoot的介绍以及优点这里就不说了,想了解的可以直接点击这里 Spring Boot百度百科 接下来我们直奔主题,开始用S ...
- SpringBoot + Spring Security 简单入门
这篇文章主要介绍了SpringBoot + Spring Security 简单入门 Spring Security 基本介绍 这里就不对Spring Security进行过多的介绍了,具体的可以参考 ...
- SpringBoot入门建站全系列(二十七)WebSocket做简单的聊天室
SpringBoot入门建站全系列(二十七)WebSocket做简单的聊天室 一.概述 WebSocket 是一种网络通信协议.RFC6455 定义了它的通信标准. WebSocket 是 HTML5 ...
- Marco's Java【SpringBoot入门(六) 之 Thymeleaf模板引擎的使用】
前言 本节呢给大家介绍一个新鲜 "玩意儿" 叫做Thymeleaf,Thymeleaf翻译过来就是 "百里香叶" 的意思 我发现这些大佬儿特别喜欢用叶子作为标识 ...
最新文章
- ComponentOne Ultimate 2020中文版
- [Swift]LeetCode826. 安排工作以达到最大收益 | Most Profit Assigning Work
- 2018年春阅读计划---阅读笔记4
- 一次简单的服务器 cpu 占用率高的快速排查实战
- php常用算法的时间复杂度,php的几个经典排序算法及时间复杂度和耗时​
- #把函数当作参数传给另一个函数
- C#中List的排序(Sort)
- extend 和 append 的区别
- SVN使用过程中出现“工作副本已经锁定”的解决办法
- 冯诺依曼计算机主机,冯诺依曼计算机的基本思想是什么?
- (十五)final关键字
- data-bi(3):大数据分析软件 CBoard有了一个另外的ui,vuejs写的
- STM32数据可视化显示——纸飞机串口调试助手的使用
- 完全自学C(干货) —— 结构体初识
- oracle12c 查看库,12c 检查pdb数据库状态
- 微信小程序给公众号发送模板消息
- Markdown编辑器 - 字体颜色表(颜色名、十六进制颜色值、颜色)
- localStorage的使用方法
- WinForm自制水晶按钮
- 用python实现相声、评书自动下载(一)