thymeleaf 相关问题

Thymeleaf是一个XML / XHTML / HTML5模板引擎(可扩展到其他格式),可以在Web和非Web环境中工作。它更适合在Web应用程序的视图层提供XHTML / HTML5,它甚至可以在脱机环境中处理任何XML文件。它提供了一个可选模块,用于与Spring MVC集成,因此您可以在使用此技术的应用程序中将其用作JSP的完全替代,即使使用HTML5也是如此。

Thymeleaf 表单传递空对象

我对 Spring Web 和 Thymeleaf 很陌生,我正在尝试创建一个表单,将 Todo 对象传递给控制器,控制器将该对象保存到数据库中。表单接受输入,但接受实际对象

回答 1 投票 0

Thymeleaf 在 Spring Boot 应用程序中不显示来自 base64 字符串的图像

我有一个 Spring Boot 应用程序,我使用 Thymeleaf 在前端显示作为 base64 字符串接收的图像。然而,尽管将 base64 字符串传递给 Thymeleaf,但图像并不是......

回答 1 投票 0

子目录中的 springboot thymeleaf 模板

我已经构建了一个简单的 SpringBoot 应用程序,如下所述: https://spring.io/guides/gs/spring-boot/ 我能够让它工作并测试所有端点,包括 /hello,这需要用户......

回答 1 投票 0

将 Thymeleaf 片段作为参数传递给另一个片段时“选择器与选择器语法不匹配”

我想为所有页面提供一个共享模板,例如每个页面上都会张贴一个绿色框架。我有一个带有蓝色框架的索引页。所以我创建片段/整个页面....

回答 1 投票 0

Thymeleaf 不显示我的迭代器的所有对象

我最近正在研究百里香,我的一个大学项目需要一些帮助。基本上我必须应用迭代器模式设计来迭代对象列表,然后将它们打印在视频上......

回答 1 投票 0

Spring Boot - 重定向到不同的控制器方法

我正在使用 SpringBoot 和 Thymeleaf 创建一个非常基本的应用程序。在控制器中我有两种方法,如下所示: 方法1 - 此方法显示数据库中的所有数据: @RequestMappi...

回答 5 投票 0

thymeleaf 添加 html 转义字符

我正在尝试向 plausibles api 发送一个事件来跟踪收入。问题是百里香逃避了价格。这会导致api无法获取正确的信息。 问题...

回答 1 投票 0

Spring CRUD 不将实体保存到数据库

我的 Spring 应用程序不向连接的 H2 数据库添加任何数据。 这是我的患者实体: 包装医疗.型号; 导入 jakarta.persistence.*; 导入 jakarta.validation.constraints.NotBlank; 导入

回答 1 投票 0

Thymeleaf 在 html 页面中不显示数据

我正在研究 Thymeleaf,我不明白为什么我无法在 html 代码中显示数据。 我的 Thymeleaf 控制器如下: @控制器 公共类用户控制器{ @GetMapping("...

回答 1 投票 0

Thymeleaf:串联 - 无法解析为表达式

我在尝试在模板中连接多个值时遇到问题。 根据 Thymeleaf 的说法,我应该能够将它们+在一起...... 4.6 连接文本 文字,无所谓

回答 5 投票 0

模板解析期间出现内部服务器错误。发生什么事了?

因此,我正在构建一个简单的炸玉米饼订单应用程序,当我在 /design 提交表单时,出现了“模板解析”错误。 [[端点订单错误/当前](https://i.stack.imgur.com/ujN8...

回答 1 投票 0

thymeleaf 如何找到模板位置?

当我启动 Spring Boot 应用程序时,我收到警告,如下所示: 2023-02-16T13:26:47.508-05:00 警告 23919 --- [restartedMain] DefaultTemplateResolverConfiguration 找不到模板位置:

回答 2 投票 0

将 Thymeleaf 变量处理为 HTML 代码而不是文本

我正在使用 Thymeleaf 处理 html 模板,我了解如何从控制器附加内联字符串,但现在我想将 HTML 代码片段附加到页面中。 例如,让我们留在...

回答 4 投票 0

计算 Thymeleaf if 语句在循环中计算为 true 的次数

我有一个 thymeleaf 模板,它迭代列表(杂务完成对象),并在满足 if 条件时打印一封信(当杂务完成对象具有特定的 Chore_id 和 person_i...

回答 1 投票 0

我可以在 h2 数据库中创建表,但似乎无法使用 data.sql 文件中的静态数据填充它

我对 Spring 还很陌生,我正在关注的在线讲座有点过时了。我制作了一个非常简单的 html 表单,可以将数据添加到数据库中。我可以制作表格,但无法填充...

回答 1 投票 0

如何使用 Thymeleaf 模板中的抽象类到 Spring boot 控制器?

我的应用程序有这个结构模型: 公共类车库 列出车辆; ... 公共抽象类车辆 列出轮子 ... 公共课 Car 扩展了 Veh...

回答 1 投票 0

如何使用 Thymeleaf 有条件地从 a 标签中完全删除 href 属性?

在 Thymeleaf 模板中,我想根据给定条件删除 href 属性。我尝试了以下操作,但 href 仍然存在,尽管没有内容: 在 Thymeleaf 模板中,我想根据给定条件删除 href 属性。我尝试了以下操作,但 href 仍然存在,尽管没有内容: <a th:href="@{ ${ canUpdatePassword ? '/password/update' : _} }">Forgot password?</a> 要将链接从浏览器选项卡方案中完全删除,必须省略 href,以便链接被标记为占位符。我如何使用 Thymeleaf 来实现这一目标,并且没有任何 JS 来实现这一点? 非常感谢 最简单的方法可能就是使用th:if。我想不出任何其他方法来实现这一目标。 <a th:if="${canUpdatePassword}" th:href="@{'/password/update'}">Forgot password?</a> <a th:unless="${canUpdatePassword}">Forgot password?</a>

回答 1 投票 0

Spring Boot 验证消息在编译期间解析

我已经为 i18n 设置了 Spring Boot Validation Message,其中包含各种必要的注释和 bean,并使其全部正常工作,例如 一些POJO @NotEmpty(message = "{user.lastname_required...

回答 1 投票 0

th:在 Thymeleaf 的选择/选项中选择一个数字不起作用

我有这个代码 Attivita'&l... 我有这个代码 <div th:class="form-group"> <td><label class="control-label leftMargin10 rightMargin10" scope="col" th:text="#{insertHours.hhFrom}">Attivita'</label></td> <td><select class="form-control" th:field="*{hhFrom}"> <option th:each="i : ${#numbers.sequence(0, 23)}" th:value="${i}" th:text="${i}" th:selected="${ i==9 } ">Options</option> </select> </td> </div> 当我尝试在 th:selected 中添加条件时,它不起作用。 我也用这个代码替换了: th:attr="${i==9}? selected=selected: '' " 但结果是一样的。 HTML <select class="form-control" id="hhFrom" name="hhFrom"> <option value="0" selected="selected">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> </select> 提前感谢您的回答 您不能将 th:field 与 th:selected 一起使用。 如果将 th:field 替换为 name=someMeaningfullName,代码将正常工作。 查看 Thymeleaf 论坛上的 this 主题,了解更多信息 另一个非常简单且有效的技巧是关闭选择标签:<select ... /> 请注意第一行末尾的/>: <select th:field="*{percentage}" /> <option th:each="i : ${#numbers.sequence(0, 100)}" th:value="${i}" th:text="${i}" th:selected="${i==75}"></option> </select> 渲染为: <select id="percentage" name="percentage" /> <option value="0">0</option> <option value="1">1</option> ... <option value="74">74</option> <option value="75" selected="selected">75</option> <option value="76">76</option> ... <option value="100">100</option> </select> 网络浏览器和 Thymeleaf 都能很好地处理这个问题。 我用了Thymeleaf v。3.0.9.RELEASE 我还发现,如果您在选项字段周围放置 <div> 标签,selected="selected" 也会起作用。例如 <select th:field="*{name}"> <div> <option disabled="true" selected="selected" value="">Select</option> <option value="1">first</option> <option value="2">second</option> </div> </select>

回答 3 投票 0

如何使用 thymeleaf 扩展我的模板?

我想要一个在一页中显示这两个文件的视图。我遵循了语法,但仍无法获得正确的视图。 布局页面: 我想要一个在一页中显示这两个文件的视图。我遵循了语法,但仍无法获得正确的视图。 布局页面: <!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"> <body> <div layout:fragment="content"> <p>Changing contents</p> </div> </body> </html> 内容页: <!DOCTYPE html> <html lang="en" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="skeleton.html" xmlns:th="http://www.thymeleaf.org"> <body> <div layout:fragment="content"> <!--Content of the page--> <h3>page injected in another page</h3> </div> </body> </html> 结果就是包含以下文本的内容页面的内容: 页面已注入另一个页面 有人可以告诉我我的代码有什么问题吗? 对于layout:decorate,您需要使用标准表达式语法,类似...layout:decorate="~{skeleton}"将起作用,具体取决于您的skeleton.html文件的位置。 看起来 Thymeleaf 3.1 版模板扩展应该使用教程:使用 Thymeleaf (3.1.2.RELEASE),第 8.5 章布局继承中描述的其他机制来完成: 布局是(src/main/resources/templates/layout/layout_simple.html): <!DOCTYPE html> <html lang="en" th:fragment="layout(title, main)" xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title th:replace="${title}">Layout title</title> </head> <body> <header>Common block: header</header> <main id="mainpart" th:replace="${main}"> <p><em>This content must not be visible.</em></p> </main> <footer>Common block: footer</footer> </body> </html> 页面是(src/main/resources/templates/thymeleaf_first_page_simple.html): <!DOCTYPE html> <html th:replace="~{layout/layout_simple :: layout(~{::title}, ~{::main})}" xmlns:th="http://www.thymeleaf.org"> <head> <title>Thymeleaf demo simple</title> </head> <body> <main> <h1>Thymeleaf template extension simple demo</h1> <p>Actual page content: [<th:block th:text="${modelValue}" />]</p> </main> </body> </html> 结果是: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Thymeleaf demo simple</title> </head> <body> <header>Common block: header</header> <main> <h1>Thymeleaf template extension simple demo</h1> <p>Actual page content: [some simple value from the model]</p> </main> <footer>Common block: footer</footer> </body> </html>

回答 2 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.