介绍

以下总结了使用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实战总结的更多相关文章

  1. SpringBoot基础实战系列(一)整合视图

    SpringBoot整合freemarker 1.添加依赖:springboot基本上是无缝衔接,基本上只需要添加对应的依赖,不需要或者做很少量的配置即可 注:对于springboot项目的创建此处不 ...

  2. SpringBoot基础实战系列(三)springboot单文件与多文件上传

    springboot单文件上传 对于springboot文件上传需要了解一个类MultipartFile ,该类用于文件上传.我此次使用thymeleaf模板引擎,该模板引擎文件后缀 .html. 1 ...

  3. Springboot+thymeleaf结合Vue,通过thymeleaf给vue赋值解决Vue的SEO问题

    前言 vue开发的项目有时候会有SEO的需求,由于vue是JavaScript框架,内容都在JavaScript和服务端,所以SEO效果很差.vue的服务端渲染又很难和现在成熟的springboot等 ...

  4. 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类中的方法,又多此一举的单独整 ...

  5. springboot+thymeleaf+pageHelper带条件分页查询

    html层 <div> <a class="num"><b th:text="'共 '+ ${result.resultMap['pages ...

  6. 【SpringBoot】Logback日志框架介绍和SpringBoot整合实战

    ========================11.Logback日志框架介绍和SpringBoot整合实战 2节课================================ 1.新日志框架L ...

  7. springboot+thymeleaf简单使用

    关于springboot想必很多人都在使用,由于公司项目一直使用的是SpringMVC,所以自己抽空体验了一下springboot的简单使用. 环境搭建 springbooot的环境搭建可以说很灵活, ...

  8. SpringBoot thymeleaf使用方法,thymeleaf模板迭代

    SpringBoot thymeleaf使用方法,thymeleaf模板迭代 SpringBoot thymeleaf 循环List.Map ============================= ...

  9. SpringBoot thymeleaf模板页面没提示,SpringBoot thymeleaf模板插件安装

    SpringBoot thymeleaf模板插件安装 SpringBoot thymeleaf模板Html页面没提示 SpringBoot  thymeleaf模板页面没提示 SpringBoot t ...

  10. SpringBoot thymeleaf模板版本,thymeleaf模板更换版本

    SpringBoot thymeleaf模板版本 thymeleaf模板更换版本 修改thymeleaf模板版本 ================================ ©Copyright ...

随机推荐

  1. [转帖]RHEL/CentOS 7的systemd target及其中的multi-user.target

    在RHEL/CentOS 6中,使用SysV init和Upstart,通过预定义一组Runlevels(从0到6)表示不同的执行模式. [root@myhost app]# ll /etc/rc.d ...

  2. [转帖]信创从芯开始,CPU实现国产有多难?

    https://www.eet-china.com/mp/a213516.html 数字底座的"底座"--CPU,决定信创底层逻辑的关键.CPU 是信息产业中最基础的核心部件,指令 ...

  3. [转帖]/proc文件简介

    https://www.jianshu.com/p/2610241770be 简介 /proc文件系统是一个伪文件系统,它只存在内存当中,而不占用外存空间.它以文件系统的方式为访问系统内核数据的操作提 ...

  4. ipset的学习与使用

    ipset的学习与使用 场景说明 虽然可以通过: firewall-cmd --zone=trusted --add-source=$1 --permanent && firewall ...

  5. 基于Spring Cache实现Caffeine、jimDB多级缓存实战

    作者: 京东零售 王震 背景 在早期参与涅槃氛围标签中台项目中,前台要求接口性能999要求50ms以下,通过设计Caffeine.ehcache堆外缓存.jimDB三级缓存,利用内存.堆外.jimDB ...

  6. vue3跟新视图遇见神奇现象

    场景描述 今天遇见一个问题, tableAllFun 函数中写了一个 index=1; 然后在 otherAllFun 函数中去改变这个index=2的值 奇怪的事情发生了 在视图index展示的值是 ...

  7. VictoriaMetrics 1.73.1 值得关注的新特性

    作者:张富春(ahfuzhang),转载时请注明作者和引用链接,谢谢! cnblogs博客 zhihu 公众号:一本正经的瞎扯 VictoriaMetrics 1.73.1 的changelog: h ...

  8. 强大的AWS lambda

    AWS强大的lambda 自从几年前换工作后,我所参与的项目一直都是基于AWS云服务的架构,我慢慢对serverless的相关基础建设有了一定了解和实践经验.其中lambda是我心中最强大的serve ...

  9. vscode中文搜索乱码或搜索不到

    使用vscode在全局搜索时,代码中的内容无法搜索出来,或者搜索出来是乱码. 经验证:与vscode的语言设置无关,设置为中文或英文都是一样的 后面猜想到会不会与文件自身的编码有关,因为我们项目中的代 ...

  10. vim 从嫌弃到依赖(9)——命令模式进阶

    上一篇文章更新还是在51前,最近发生了很多事情了,全国各地的疫情又有蔓延的趋势,北京朝阳区都已经开始实施居家办公.各位小伙伴请注意安全,安全平安的度过这个疫情. 废话不多说了,接着上次的内容往下写. ...