Springboot thymeleaf实战总结
介绍
以下总结了使用Thymeleaf做项目过程中碰到的有价值的知识点。拿出来分享!
1.配置context-path
- 在公共模板中添加:
<script type="text/javascript" th:inline="javascript" th:fragment="ctx">
/*<![CDATA[*/
var ctx = /*[[@{/}]]*/ '';
/*]]>*/
</script>
- 在需要ctx的页面中添加
<!--ctx-->
<script th:replace="~{fragment::ctx}"/>
2.遍历list
<a th:each="n,newsStat : ${newsList}" th:href="|/news/${n.id}|"
class="list-group-item">
<h5 class="mb-1" th:text="${n.getTitle()}">时政微视频丨与光同行</h5>
<small th:text="${n.getCreateTime()}">2021.12.1,阅读:123</small>
</a>
- 状态变量
<tr th:each="prod,iterStat : ${prods}" th:class="${iterStat.odd}? 'odd'">
<td th:text="${prod.name}">Onions</td>
<td th:text="${prod.price}">2.41</td>
<td th:text="${prod.inStock}? #{true} : #{false}">yes</td>
</tr>
3.th:href字符串和变量混合拼接
th:href="|/list?l=${lid}|"
4.datetime格式化
th:text="${#dates.format(n.createTime,'yyyy-MM-dd HH:mm:ss')}"
5.输出html内容
<div class="col-9" th:utext="${news.content}"></div>
6 下拉选择列表

/**
* 新增新闻
*/
@GetMapping("/add")
public String add(ModelMap map)
{
// 新闻分类列表
map.put("newsTypeList",newsTypeService.selectDmNewsTypeList(null));
return prefix + "/add";
}
- 新增
<div class="form-group">
<label class="col-sm-3 control-label">新闻分类:</label>
<div class="col-sm-8">
<!--<input name="newsTypeId" class="form-control" type="text">-->
<select name="newsTypeId" id="newsTypeId" lay-verify="required" class="form-control">
<option th:each="t:${newsTypeList}" th:value="${t.id}"
th:text="${t.typeName}"></option>
</select>
</div>
</div>
- 编辑回显
<select name="newsTypeId" id="newsTypeId" lay-verify="required" class="form-control">
<option th:each="t:${newsTypeList}" th:value="${t.id}"
th:text="${t.typeName}"></option>
</select>
Springboot thymeleaf实战总结的更多相关文章
- SpringBoot基础实战系列(一)整合视图
SpringBoot整合freemarker 1.添加依赖:springboot基本上是无缝衔接,基本上只需要添加对应的依赖,不需要或者做很少量的配置即可 注:对于springboot项目的创建此处不 ...
- SpringBoot基础实战系列(三)springboot单文件与多文件上传
springboot单文件上传 对于springboot文件上传需要了解一个类MultipartFile ,该类用于文件上传.我此次使用thymeleaf模板引擎,该模板引擎文件后缀 .html. 1 ...
- Springboot+thymeleaf结合Vue,通过thymeleaf给vue赋值解决Vue的SEO问题
前言 vue开发的项目有时候会有SEO的需求,由于vue是JavaScript框架,内容都在JavaScript和服务端,所以SEO效果很差.vue的服务端渲染又很难和现在成熟的springboot等 ...
- org.springframework.expression.spel.SpelEvaluationException: EL1004E: Method call: Method service() cannot be found on com.my.blog.springboot.thymeleaf.util.MethodTest type
前言 本文中提到的解决方案,源码地址在:springboot-thymeleaf,希望可以帮你解决问题. 至于为什么已经写了一篇文章thymeleaf模板引擎调用java类中的方法,又多此一举的单独整 ...
- springboot+thymeleaf+pageHelper带条件分页查询
html层 <div> <a class="num"><b th:text="'共 '+ ${result.resultMap['pages ...
- 【SpringBoot】Logback日志框架介绍和SpringBoot整合实战
========================11.Logback日志框架介绍和SpringBoot整合实战 2节课================================ 1.新日志框架L ...
- springboot+thymeleaf简单使用
关于springboot想必很多人都在使用,由于公司项目一直使用的是SpringMVC,所以自己抽空体验了一下springboot的简单使用. 环境搭建 springbooot的环境搭建可以说很灵活, ...
- SpringBoot thymeleaf使用方法,thymeleaf模板迭代
SpringBoot thymeleaf使用方法,thymeleaf模板迭代 SpringBoot thymeleaf 循环List.Map ============================= ...
- SpringBoot thymeleaf模板页面没提示,SpringBoot thymeleaf模板插件安装
SpringBoot thymeleaf模板插件安装 SpringBoot thymeleaf模板Html页面没提示 SpringBoot thymeleaf模板页面没提示 SpringBoot t ...
- SpringBoot thymeleaf模板版本,thymeleaf模板更换版本
SpringBoot thymeleaf模板版本 thymeleaf模板更换版本 修改thymeleaf模板版本 ================================ ©Copyright ...
随机推荐
- [转帖]LVS入门篇(五)之LVS+Keepalived实战
LVS入门篇(五)之LVS+Keepalived实战 https://www.cnblogs.com/linuxk/p/9365189.html 一.实验架构和环境说明 (1)本次基于VMware W ...
- [转帖][github]Chinese-LLaMA-Alpaca Public
`https://github.com/ymcui/Chinese-LLaMA-Alpaca#%E6%A8%A1%E5%9E%8B%E4%B8%8B%E8%BD%BD` 以ChatGPT.GPT-4等 ...
- 【转帖】一道面试题:JVM老年代空间担保机制
面试问题 昨天面试的时候,面试官问的问题: 什么是老年代空间担保机制?担保的过程是什么? 老年代空间担保机制是谁给谁担保? 为什么要有老年代空间担保机制?或者说空间担保机制的目的是什么? 如果没有老年 ...
- [转帖]总结:SpringBoot启动参数配置
一.背景 由于项目中加了bootstrap.properties文件,且文件中有变量,如spring.cloud.config.profile=${spring.profiles.active},而b ...
- Linux 排除某些目录下 重复jar包的方法
Linux 排除某些目录下 取重复jar包的方法 find . -path ./runtime/java -prune -o -name '*.jar' -exec basename {} \;| s ...
- CTT Day3
T1 忘了叫什么名字 对于一个排列 \(p\),定义它的权值为其有多少个子串是一个值域从 \(1\) 开始的排列.给定排列 \(p\),对于 \(1\le i\le j\le n\),定义 \(f(i ...
- Sqlite管理工具
! https://zhuanlan.zhihu.com/p/375188242 SQLiteStudio 开源免费的一款sqlite数据库管理软件,支持windows,linux,macos 官网: ...
- TienChin 渠道管理-表创建
在若依当中,有个槽点,就是数据库当中的删除标识状态一般 0 是 false,1 是 true,在若依当中反而 0 是 true,1 是 false. 渠道表设计,我这里就直接贴成品的创建表 SQL: ...
- 设计模式学习-使用go实现中介者模式
中介模式 定义 优点 缺点 适用范围 代码实现 参考 中介模式 定义 中介模式(Mediator):用一个中介对象来封装一系列的对象交互.中介者使个各对象不需要显示的相互引用,从而使其藕合松散,而且可 ...
- 3.2 DLL注入:远程APC异步注入
APC(Asynchronous Procedure Call)异步过程调用是一种Windows操作系统的核心机制,它允许在进程上下文中执行用户定义的函数,而无需创建线程或等待OS执行完成.该机制适用 ...