SpringBoot2 学习5集成Thymeleaf
整个项目文件结构
API 参考地址:https://www.e-learn.cn/thymeleaf/standard-dialects
POM
关键:
org.springframework.boot
spring-boot-starter-thymeleaf
<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><parent><groupId>zz</groupId><artifactId>SpringBoot2</artifactId><version>0.0.1-SNAPSHOT</version></parent><artifactId>SpringBootThymeleaf</artifactId><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!--目的:《可选》引入springboot 热启动,每次修改以后,会自动把改动加载,不需要重启服务了--><dependency> <groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><optional>true</optional></dependency><!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.15</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId></dependency></dependencies><repositories><repository><id>alimaven</id><name>aliyun maven</name><url>http://maven.aliyun.com/nexus/content/groups/public/</url></repository></repositories><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build>
</project>
Controller
package com.zz.controller;import java.util.ArrayList;
import java.util.List;import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;import com.zz.entity.Account;@Controller
public class IndexController {@RequestMapping("/account")public String index(Model m) {List<Account> list = new ArrayList<Account>();list.add(new Account("KangKang", "康康", "e10adc3949ba59abbe56e", "超级管理员", "17777777777"));list.add(new Account("Mike", "麦克", "e10adc3949ba59abbe56e", "管理员", "13444444444"));list.add(new Account("Jane","简","e10adc3949ba59abbe56e","运维人员","18666666666"));list.add(new Account("Maria", "玛利亚", "e10adc3949ba59abbe56e", "清算人员", "19999999999"));m.addAttribute("accountList",list);return "account";}
}
template
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head><title>account</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><link rel="stylesheet" th:href="@{/css/style.css}" type="text/css">
</head>
<body><table><tr><th>no</th><th>account</th><th>name</th><th>password</th><th>accountType</th><th>tel</th></tr><tr th:each="list,stat : ${accountList}"><td th:text="${stat.count}"></td><td th:text="${list.account}"></td><td th:text="${list.name}"></td><td th:text="${list.password}"></td><td th:text="${list.accountType}"></td><td th:text="${list.tel}"></td></tr></table>
</body>
</html>
测试效果
语法
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>demo1</title>
</head>
<body><h1>${...} : 变量表达式。 演示</h1><h3>1 取值,直接显示</h3>
<span >你好</span><span th:text="${helloname}"></span><h3>2 对象,显示</h3><span th:text="${a.name}"></span><h3>3 List,显示</h3>
遍历(迭代)的语法th:each="自定义的元素变量名称 : ${集合变量名称}":
状态变量的使用语法:th:each="自定义的元素变量名称, 自定义的状态变量名称 : ${集合变量名称}":
不管什么时候,Thymeleaf 始终会为每个th:each创建一个状态变量,
默认的状态变量名称就是自定义的元素变量名称后面加Stat字符串组成<table border="1">
<tr>
<th>名字</th>
<th>电话</th>
</tr><tr th:each="c:${cs}"><td th:text="${c.name}"></td><td th:text="${c.tel}"></td>
</tr></table></body>
</html>
controller
package com.zz.controller;import java.util.ArrayList;
import java.util.List;import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;import com.zz.entity.Account;@Controller
@RequestMapping("/thymeleaf")
public class DemoController {@RequestMapping("/demo1")public String to_demo1(Model m) {m.addAttribute("helloname", "jerry");Account account=new Account();account.setName("小明");m.addAttribute("a", account);Account account1=new Account();account1.setName("小明");account1.setTel("23424");Account account2=new Account();account2.setName("小红");account2.setTel("322");Account account3=new Account();account3.setName("小王");account3.setTel("111");List<Account> clist=new ArrayList();clist.add(account1);clist.add(account2);clist.add(account3);m.addAttribute("cs", clist);return "demo1";}
}
SpringBoot2 学习5集成Thymeleaf相关推荐
- SpringBoot2.x 集成 Thymeleaf
本文主要对SpringBoot2.x集成Thymeleaf及其常用语法进行简单总结,其中SpringBoot使用的2.4.5版本. 一.Thymeleaf简介 Thymeleaf是面向Web和独立环境 ...
- springboot2 war页面放在那_成为微服务架构师--SpringBoot2学习笔记
<"爱读书"--给你讲技术>,我来看书,你来进步,让我们开始吧! 本书简介 书名为<SpringBoot2企业应用实战>,这是一本简单易懂的SpringBo ...
- thymeleaf依赖_玩转SpringBoot集成 Thymeleaf 模版引擎
随着互联网技术的发展,在前后端分离开发模式已经逐渐成为主流的今天,前后端技术的划分也越来越清晰,社会分工进一步细化,职业岗位也更加细分,慢慢开始就有了前端攻城狮和后端攻城狮,技术也进一步细分,出现了以 ...
- 深度学习框架集成平台C++ Guide指南
深度学习框架集成平台C++ Guide指南 这个指南详细地介绍了神经网络C++的API,并介绍了许多不同的方法来处理模型. 提示 所有框架运行时接口都是相同的,因此本指南适用于所有受支持框架(包括Te ...
- Spark 2.4重磅发布:优化深度学习框架集成,提供更灵活的流式接收器
Apache Spark 2.4.0是2.x系列中的第五个版本.此版本增加了屏障执行模式,以便更好地与深度学习框架集成:引入30多个更高阶的内置函数,能够更轻松地处理复杂数据类型:优化K8s集成,同时 ...
- 【深度学习】解析深度学习的集成方法
[深度学习]解析深度学习的集成方法 文章目录 1 前言 2 使用集成模型降低方差 3 如何集成神经网络模型3.1 Varying Training Data3.2 Varying Combinatio ...
- 集成学习-Boosting集成学习算法GBDT
GBDT算法的核心为:先构造一个(决策)树,然后不断在已有模型和实际样本输出的残差上再构造一颗树,依次迭代. 目录 Decistion Tree(决策树) Gradient Boosting(梯度提升 ...
- 九、SpringBoot集成Thymeleaf模板引擎
Thymeleaf咋读!??? 呵呵,是不是一脸懵逼...哥用我的大学四级英文知识告诉你吧:[θaimlif]. 啥玩意?不会音标?...那你就这样叫它吧:"赛母李府",大部分中国 ...
- springboot2.1.5集成finereport10.0过程中:手动安装本地jar包到maven仓库
springBoot2.1.5集成finereport10.0过程中,pom依赖中需要用到finereport安装路径下的jar包,主要有:以fine开头的jar包 按住Ctrl+Shift在空白位置 ...
- SpringBoot2.6.x集成swagger: Failed to start bean ‘documentationPluginsBootstrapper问题解决
在使用SpringBoot2.6.x集成swagger的时候,启动的时候出现了:Failed to start bean 'documentationPluginsBootstrapper 的空指针异 ...
最新文章
- php如何添加超链接,如何使用phpcms添加超链接
- java 面试题 简书_java面试题
- android锁屏显示应用程序,今日应用:微软又给 Android 做了一款锁屏应用
- Qt Creator用户互动方法
- lamp mysql开机自启_centos下设置自启动和配置环境变量的方法
- 一只蝙蝠的自述在朋友圈火了:千万不要再吃野味了!
- 【CodeForces - 705C】Thor(模拟,STLset优化链表)
- [项目回顾]基于Annotation与SpringAOP的缓存简单解决方案
- Android定时器AlarmManager(定时发送广播)
- 面试之手撕BP反向传播
- 免费思维导图工具推荐,办公必备
- 领域建模——事件风暴
- mac 运行android模拟器速度慢,Mac下顺畅的安卓模拟器:网易MuMu
- 网络监控解决方案及拓扑图
- 2023年计算机专业毕业设计选题有哪些?(附源码)
- 【逻辑】笔面试 | 智力题整理
- tp6使用workman实现定时任务
- 微信小程序自动检测新版本并静默更新,及热启动和冷启动
- SIGIR2022 | 基于Prompt的用户自选公平性推荐算法
- 熊太行.关系攻略之---正确认识关系和自己
热门文章
- 系统安装部署系列教程(六):封装系统
- 【Tensorflow 报错】struct.error: 'i' format requires -2147483648 = number = 2147483647
- 网络安全行业全领域白皮书
- 美国次贷危机[百科]
- html 外联 变 内联,Html 内联元素、外联元素 和 可变元素
- csb反编译_GitHub - lyzz0612/csb2csd: cocostudio csb反编成csd
- 阿里巴巴Mysql规范
- 彻底理解“EBIT、EBITDA与净利润 ”| 联系与区别
- 【CSS应用篇】——CSS如何实现渐变背景
- 练习4闭合导线平差计算