解决方法:

先将模板路径放置templates目录下,发现可以访问,说明th:replace是可以用的。

那可能是出现在路径问题上面。

于是我开始调错,改路径。

后来在网上查找资料。说了很多种方法。

第一种,见截图:

springboot+thymeleaf项目中使用th:replace访问templates子目录下的模板,会报错找不到模板路径

 

 但上面应该写错了,不应该是ServletContextTemplateResolver,而应该是SpringResourceTemplateResolver。而且应该交给spring容器进行管理,而不是放在构造方法中。

另外第二种方案就是:

尝试不带〜{}的情况调用th:replace

<div th:replace="fragments/fragment1 :: fr1"></div>

具体可以参考:

https://blog.csdn.net/Jalon2015/article/details/60961117

https://www.icode9.com/content-1-561664.html

我是选择的第二种方案。。。简单

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-05
  • 2022-02-22
  • 2022-12-23
  • 2022-12-23
  • 2021-06-14
猜你喜欢
  • 2022-01-08
  • 2021-10-12
  • 2022-12-23
  • 2021-12-03
  • 2022-12-23
  • 2021-12-12
  • 2022-12-23
相关资源
相似解决方案