弹簧靴& thymeleaf

时间:2017-08-23 15:21:18

标签: spring-boot thymeleaf

我使用spring boot 1.5.6 release和thymeleaf 3.0.0.release,thymeleaf-layout-dialect 2.0.0。

我写了一个html文件,如下所示。 enter image description here

header_top和footer_bottom是另外两个html文件,内容是: enter image description here

enter image description here

我有一个控制器,很简单:

enter image description here

开始申请如下:

enter image description here

the applications.properties file cotains contents below: 
spring.thymeleaf.mode=HTML5
spring.thymeleaf.cache=false
spring.session.store-type=none

logging.level.root=INFO
logging.level.org.springframework.web=DEBUG
debug=true

当我运行应用时,我将http://localhost:8080放在Chrome地址栏中。我得到的是你好世界。所以我猜春季靴子&amp; thymeleaf模板解析器可以找到index.html文件。但是header_top::catelogfooter_bottom::copy根本没有被解析。我通过chrome dev工具检查了页面的源代码。 <div th:insert...就像在模板文件中一样。所以我想根本没有解析th:*。我是春季靴子和百里香的新手。我已经google了很长时间,但仍然无法找到解决方案。

请有人帮助我。

请求发生时,日志如下:

2017-08-25 10:56:35.023 DEBUG 34177 --- [nio-8080-exec-3] o.s.b.w.f.OrderedRequestContextFilter : Bound request context to thread: org.apache.catalina.connector.RequestFacade@6333b70f 2017-08-25 10:56:35.024 DEBUG 34177 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/] 2017-08-25 10:56:35.024 DEBUG 34177 --- [nio-8080-exec-3] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path / 2017-08-25 10:56:35.024 DEBUG 34177 --- [nio-8080-exec-3] s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method [public java.lang.String com.easylife.haozu.controller.IndexController.index(org.springframework.ui.Model)] 2017-08-25 10:56:35.024 DEBUG 34177 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet : Last-Modified value for [/] is: -1 2017-08-25 10:56:35.024 DEBUG 34177 --- [nio-8080-exec-3] o.s.w.s.v.ContentNegotiatingViewResolver : Requested media types are [text/html, application/xhtml+xml, image/webp, image/apng, application/xml;q=0.9, */*;q=0.8] based on Accept header types and producible media types [*/*]) 2017-08-25 10:56:35.024 DEBUG 34177 --- [nio-8080-exec-3] o.s.w.servlet.view.BeanNameViewResolver : No matching bean found for view name 'index' 2017-08-25 10:56:35.025 DEBUG 34177 --- [nio-8080-exec-3] o.s.w.s.v.ContentNegotiatingViewResolver : Returning [org.thymeleaf.spring4.view.ThymeleafView@64c00234] based on requested media type 'text/html' 2017-08-25 10:56:35.025 DEBUG 34177 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet : Rendering view [org.thymeleaf.spring4.view.ThymeleafView@64c00234] in DispatcherServlet with name 'dispatcherServlet' 2017-08-25 10:56:35.028 DEBUG 34177 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet : Successfully completed request 2017-08-25 10:56:35.028 DEBUG 34177 --- [nio-8080-exec-3] o.s.b.w.f.OrderedRequestContextFilter : Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@6333b70f

2 个答案:

答案 0 :(得分:0)

你能以这种方式尝试插入吗?

PropertyAccessor.GetProperty

<div th:insert="header_top :: catalog"></div>

此外,header_top.html中的命名空间不正确,应该是:

<div th:insert="footer_bottom :: copy"></div>

如果您删除未使用的xmlns:layout,可能会很棒,以防万一。

答案 1 :(得分:0)

尝试插入像这样的片段:

 <div th:replace="components/header_top :: catalog"></div>
 <div th:replace="components/footer_bottom :: copy"></div>

components / header_top components / footer_bottom 代表HTML片段文件的路径(例如,它应放在 templates 文件夹中你的申请)

:: 之后的目录复制是您的片段名称(应该与您的th:片段名称相同)。