spring 如何在Thymeleaf片段中动态设置路径?

pftdvrlh  于 12个月前  发布在  Spring
关注(0)|答案(1)|浏览(97)

我有以下Thymeleaf片段

<th:block th:replace="~{'/login/' + ${loginBanner} :: ${loginBanner}}"></th:block>

在控制器中,我将loginBanner设置为

model.addAttribute("loginBanner", "login-banner-unauthorized");

login-banner-unauthorized片段位于src/main/resources/templates/login/login-banner-unauthorized.html
我得到以下错误

org.thymeleaf.exceptions.TemplateInputException: Error resolving template [/login/login-banner-unauthorized], template might not exist or might not be accessible by any of the configured Template Resolvers (template: "index" - line 23, col 19)

当从InteliJ运行应用程序时,一切正常,但当我将jar部署到云时,我得到了上面的错误。

dkqlctbz

dkqlctbz1#

以下解决了此问题

<th:block th:replace="~{'login/'+${loginBanner} :: ${loginBanner}}"></th:block>

注意login前面的正斜杠被删除

相关问题