thymeleaf 相关问题

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

在 Spring Boot 应用程序中运行 jar 文件但在本地运行良好时,解析 Thymeleaf 模板文件时出错

我使用 thymeleaf 开发了一个全栈 Spring Boot 应用程序,它在本地运行良好,没有任何问题。 现在我尝试将其部署到 AWS 云,但它给了我错误 [内部服务器

回答 2 投票 0

当我在 Thymeleaf 的表单标签中一起使用 th:action 和 method 属性时,它给了我异常

这很奇怪,当我在表单标签中添加操作和方法属性时,它给了我异常,但是当我从表单标签中删除方法属性时,没有发生异常。我的意思是 当我...

回答 3 投票 0

Thymeleaf:当用户更改值时是否可以使用 th:if ?

我的页面上有一个 输入和另一个 ,并且根据用户在下拉列表中选择的内容,我想隐藏或显示其他输入。然而,两个输入都与...

回答 1 投票 0

thymeleaf fields.hasErrors div 未显示

AdminDto.java: @盖特 @塞特 @NoArgs构造函数 @AllArgsConstructor 公共类 AdminDto { @Size(min = 3, max = 10, message =“名字无效(允许 3-10 个字符”) 优先...

回答 1 投票 0

将文本与 JSON (CDATA) 中的变量与条件语句组合

我尝试使用 thymeleaf 构建动态 ld+JSON。在此我使用条件语句,这基本上是有效的。但是,不会解析条件语句内的所有变量。 我尝试使用 thymeleaf 构建动态 ld+JSON。在此我使用条件语句,这基本上是有效的。但是,条件语句内的所有变量都不会被解析。 <script type="application/ld+json" > /*<![CDATA[*/ { "@context": "https://schema.org", "@graph": [ { "@type": "Article", "@id": "https://website.de/quack/[[${quack.id}]]/#article", "publisher": { "@id": "[[${article.nickname}]]" }, [( ${article.primaryImage} == null ? '' : '"image": { "@id": "https://website.de/quack/${quack.id}/#primaryimage" }, "thumbnailUrl": "${article.primaryImage}",')] "inLanguage": "[[${quack.language}]]" } ] }; /*]]>*/ </script> 结果: {... "primaryImageOfPage": { "@id": "https://website.de/quack/${quack.id}/#primaryimage" }, "image": { "@id": "https://website.de/quack/${quack.id}/#primaryimage" }, ...} 我错过了什么,将条件语句与语句内的正确解析结合起来? 关键字是字面替换 所以最终对我有用的是使用管道而不是单引号,这可以正确解析所有变量: [( ${article.primaryImage} == null ? '' : |"image": { "@id": "https://website.de/quack/${quack.id}/#primaryimage" }, "thumbnailUrl": "${article.primaryImage}",| )]

回答 1 投票 0

如何在html脚本中调用thymeleaf自定义方言

所以基本上我尝试使用 thymeleaf 使用 ld+json 构建动态模式。为了检索相应页面的 url,我们设置了一个自定义处理器: 公共类 QuackUrlAttributeTagProc...

回答 1 投票 0

如何在内联 JavaScript 中从自定义 thymeleaf 处理器调用属性

所以基本上我尝试使用 thymeleaf 使用 ld+json 构建动态模式。为了检索相应页面的 url,我们设置了一个自定义处理器: 公共类 QuackUrlAttributeTagProc...

回答 1 投票 0

Thymeleaf 内容助手无法与 Spring Boot 配合使用

百里香内容辅助不起作用,当我在 HTML 文件中输入 th: 前缀时,只显示 th:block 提案。 百里香内容辅助不起作用,当我在 HTML 文件中输入 th: 前缀时,仅显示 th:block 提案。 <th:block 我尝试将 Thymeleaf 处理器提案移至 HTML 文件的 STS/elipse 设置中的顶部,但不起作用。 该项目是 Spring Boot + Thymeleaf,Gradle 片段: plugins { id 'org.springframework.boot' version '2.1.4.RELEASE' id 'java' } apply plugin: 'io.spring.dependency-management' repositories { mavenCentral() } dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' implementation "org.springframework.boot:spring-boot-starter-thymeleaf" implementation "org.springframework.boot:spring-boot-devtools" } 我添加了 html 命名空间: <html xmlns:th="http://www.thymeleaf.org"> 将第一个命名空间更改为另一个命名空间不起作用; 好吧,唯一的工作时间是它只是替换了 HTML 的位置... <table> <tbody> <tr th: 我遇到了同样的问题,我执行了以下步骤。 打开工作空间.metadata下的.log文件 之后打开 Thymeleaf 模板 (html):按 Ctrl+sapce 检查.log文件中的异常 就我而言,这是 groovy 运行时异常,因此我卸载并安装了 groovy 插件 重新启动 eclipse,thymeleaf 内容助手开始工作。 [ groovy.lang.GroovyRuntimeException:找不到匹配的构造函数:org.thymeleaf.extras.eclipse.contentassist.autocomplete.proposals.AttributeProcessorCompletionProposal(org.thymeleaf.extras.eclipse.dialect.xml.ElementProcessor,Integer,Integer,Boolean )] 我也面临着同样的问题,并尝试了很多东西,然后我在 .metadata/ 文件夹内的 .log 文件中看到以下错误: !ENTRY org.eclipse.equinox.p2.repository 2 0 2021-09-03 12:04:19.422 !MESSAGE Server returned lastModified <= 0 for https://raw.githubusercontent.com/thymeleaf/thymeleaf-extras-eclipse-plugin/update-site/2.1.2/content.jar 所以我基本上从链接下载了jar: https://raw.githubusercontent.com/thymeleaf/thymeleaf-extras-eclipse-plugin/update-site/2.1.2/content.jar 并通过以下方式在STS中安装此插件:帮助->安装新软件->添加-> 我使用上述步骤安装了插件,它对我有用。 我还观察到另一点,它不适用于 jdk16,它在 jdk8 上运行良好。 将以下行添加到 eclipse.ini 后,添加 Thymeleaf Nature 不会再失败,内容辅助也能正常工作: --add-opens=java.base/java.lang=ALL-UNNAMED 它可能会在未来的版本中得到修复,直到您可以在 vscode 编辑器上使用 thymeleaf 扩展作为替代方案。 自 2019 年起有新的最低要求: Java 17 基于 2023-06 或更高版本的 Eclipse IDE Thymeleaf 3 项目 Eclipse WebTools HTML 编辑器(不是新功能,而是必需的) OP的问题没有澄清使用了哪个编辑器,但我在https://github.com/thymeleaf/thymeleaf-extras-eclipse-plugin发现,与2019年一样,Eclipse WebToolsHTML编辑器 必须用于 Thymeleaf 内容辅助: 这些功能仅在 Eclipse WebTools HTML 编辑器中可用, 这可能不是 Eclipse 中 HTML 文件的默认设置 安装。要检查您是否正在使用 WTP 的 HTML 编辑器, 右键单击 HTML 文件 >> 打开方式,然后查看 HTML 编辑器是否为 已选择: 就我而言,使用 Eclipse 2023-09 和 Spring Boot 3.0.5 项目以及 Thymeleaf 3.1.1 和 Java 17 安装 WTP 确实可以在没有内容帮助的情况下解决我的问题。 请注意,您可以在“设置”>“常规”>“编辑器”>“文件关联”中更改 HTML 文件的默认编辑器,方法是选择 html 文件类型,然后选择“关联编辑器”中的 HTML 编辑器,然后单击“默认”按钮和“应用并关闭”。 在 GitHub thymeleaf-extras-eclipse-plugin 的内容辅助部分中,还提到添加 Thymeleaf 性质作为添加 html 属性的替代方法,OP 提到用于触发内容辅助。但 WTP HTML 编辑器似乎确实是一个要求,而不是一个选项。 遇到同样的问题,但升级 Spring Tools 4 后问题就消失了。

回答 6 投票 0

使用自定义 DateFormatter 配置转换服务

我正在尝试在以下文档的帮助下向我的 spring/thymeleaf 应用程序添加自定义 DateFormatter : https://web.archive.org/web/20140606082846/http://www.thymeleaf.org/doc/h...

回答 2 投票 0

如何在表中使用thymeleaf迭代(循环)?

<table> <tr th:each="product : ${data}"> <td> <input type="checkbox" name="productCode" th:value="${product.productCode}" th:text="${product.productName}" /> </td> </tr> </table> 如果有100个产品, 目前,每个产品每行垂直对齐一个。 如果我想每行打印 5 个产品,然后移动到下一行,如何使用“迭代器”? 尝试了下面的代码,但失败了 为此,出现了 iterStat 这样的东西。是一种用于跟踪迭代状态的有用机制:状态变量。 这展示了如何输出 5 个项目,然后移至新行。 <table> <tr th:each="product, iterStat : ${data}"> <td> <input type="checkbox" name="productCode" th:value="${product.productCode}" th:text="${product.productName}" /> </td> <th:block th:if="${iterStat.count % 5 == 4 and !iterStat.last}"> </tr><tr> </th:block> </tr> </table>

回答 1 投票 0

STS 4 中 Thymeleaf 插件安装错误

我无法在 Spring Boot 5 项目的 STS 中下载 thymeleaf 插件 尝试从“帮助”->“安装新软件”->“添加”->“名称”为 STS 4 安装 thymeleaf 插件,

回答 1 投票 0

IntelliJ 中用于 Spring 的 Thymleaf - URI 未注册

我的 home.html 文件显示错误:URI 未在 IntelliJ 中注册(设置|语言和框架|架构和 DTD)。 包含命名空间的 html 文件是 我的 home.html 文件显示 URI 未在 IntelliJ 中注册(设置|语言和框架|架构和 DTD)错误。 包含命名空间的 html 文件是 <!DOCTYPE html><html lang="en" xmlns:th="http://www.thymeleaf.org"> 我尝试获取外部资源,但这不起作用 运行代码时,该错误不是问题,但 IntelliJ 无法为您提供 th:* 函数的代码补全。 这是 JetBrains 有意为之,因为他们在此指定: https://www.jetbrains.com/help/idea/thymeleaf.html 为了能够在 IntelliJ IDEA 中使用 Thymeleaf 支持,请确保启用 Thymeleaf 插件。 (该插件与 IDE 捆绑在一起并默认启用。) 页面顶部写着: 此功能仅在旗舰版中支持。 我还没有找到可以为您提供 Thymeleaf 支持的社区版插件,但 Thymeleaf 可以完美工作,只是您不会从 IDE 获得任何帮助 前往: 文件|设置|插件 单击“安装 Jetbrains 插件...”。在搜索栏中找到Thymeleaf,点击安装。 需要重新启动。 添加 www 后我解决了问题。 本来我是这样添加的 -> http://thymeleaf.org 参考https://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html 换线 <html lang="en" xmlns:th="http://www.thymeleaf.org"> 到 <html lang="en" xmlns:th="http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd"> 之后点击这条线,你会发现一个灯泡 点击它,你会发现 获取外部资源 选项 单击该按钮即可解决该错误。

回答 4 投票 0

额外文本被附加到电子邮件 html 中的 href

我正在开发一个需要每天发送电子邮件的java应用程序。我正在使用 Thymeleaf 从模板构建消息正文,将结果添加到 mime BodyPart,然后将该部分设置为...

回答 1 投票 0

在 Spring Boot 应用程序中将 Thymeleaf 从 3.0 升级到 3.2

尝试使用 Spring Boot 2.7 将 Spring thymeleaf 从 3.0 单独更新到 3.2。添加了以下依赖项。 org.thymeleaf 百里香叶泉5 尝试使用 Spring Boot 2.7 将 Spring thymeleaf 从 3.0 单独更新到 3.2。添加了以下依赖项。 <groupId>org.thymeleaf</groupId> <artifactId>thymeleaf-spring5</artifactId> <version>3.1.2.RELEASE</version> 出现异常 org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.thymeleaf.spring5.view.ThymeleafView]: Unresolvable class definition; nested exception is java.lang.NoClassDefFoundError: org/thymeleaf/web/IWebExchange at com.framework.exception.ErrorAttributesTests.defaultHtmlValue(ErrorAttributesTests.java:62) 测试用例: 测试 @BeforeMethod public void setup() { mockMvc = MockMvcBuilders.standaloneSetup(new BasicErrorController(new ErrorAttributes(new ObjectMapper()), new ErrorProperties())).setViewResolvers(viewResolver()).build(); //this.mockMvc = webAppContextSetup(this.wac).build(); } public void defaultHtmlValue() throws Exception { this.mockMvc.perform(get("/error").accept(MediaType.TEXT_HTML_VALUE) .requestAttr(RequestDispatcher.ERROR_EXCEPTION_TYPE, "bar") .requestAttr(RequestDispatcher.ERROR_STATUS_CODE, 400) .requestAttr(RequestDispatcher.ERROR_REQUEST_URI, "/notes")) .andDo(print()).andExpect(status().isBadRequest()) .andExpect(content().contentType("text/html;charset=UTF-8")) .andExpect(content().string(Matchers.containsString("Something went wrong!"))); } private ViewResolver viewResolver() { ThymeleafViewResolver viewResolver = new ThymeleafViewResolver(); SpringTemplateEngine templateEngine = new SpringTemplateEngine(); ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver(); templateResolver.setPrefix("templates/"); templateResolver.setCacheable(false); templateResolver.setSuffix(".html"); templateResolver.setTemplateMode("HTML5"); templateResolver.setCharacterEncoding("UTF-8"); templateEngine.setTemplateResolver(templateResolver); viewResolver.setTemplateEngine(templateEngine); viewResolver.setCharacterEncoding("UTF-8"); return viewResolver; } 我需要将SpringBoot更新到3吗? 如果您使用 Spring Boot,请添加 spring-boot-starter-thymeleaf。 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> 这将带来 thymeleaf 所需的所有依赖项。

回答 1 投票 0

元素类型“input”必须以匹配的结束标记“</input>”结束

我在第 29 行收到错误,该行是按钮下方的表单结束标记。 org.xml.sax.SAXParseException:元素类型“input”必须由匹配的 end-t 终止...

回答 2 投票 0

如何在thymelaef中获取上下文路径

我使用 Thymeleaf 模板开发 Spring Boot 应用程序。我想在下面的代码中添加前缀(服务器上下文路径),例如“serverContext/user/”+ user.id。我尝试将 $ 更改为 @ 但 user.id 已转换...

回答 3 投票 0

Thymeleaf 表达式对象:#session 和 ${session....}

Thymeleaf 中有两种获取会话属性的方法: ${#session.getAttribute('attr')} ${会话.attr} 两个会话“对象”之间有什么区别?有没有一种情况...

回答 2 投票 0

Thymeleaf 获取 requestURI 的方法

鉴于最新的 Spring Boot 版本 + 一些额外的 thymeleaf 模块,应用程序将不再在模板中生成 requestURI。我相信这与改变有关(https://github.com/thym...

回答 1 投票 0

通过 Thymeleaf 和 itest 将 html 转换为 pdf (html2pdf)

但是当我运行测试时我遇到了这个错误: org.thymeleaf.exceptions.TemplateInputException:模板解析期间发生错误(模板:“classpath:templates/invoice_template”) ...

回答 1 投票 0

thymeleaf 3 spring 5加载css

我正在尝试一起配置Spring5和Thymeleaf3。 我正在 Eclipse 上工作,我使用全新安装进行构建并使用 springboot:run 运行应用程序。 我已经设置了一个控制器和几个模板......

回答 2 投票 0

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