我在我的应用程序中一直使用Tiles 2,Thymeleaf和Spring MVC。今天我去添加一个新片段,它似乎没有注册。我仍然得到旧模板。模板解析器似乎忽略了新的片段。我已经尝试清理我的项目,但它没有改变任何东西。有谁知道为什么我不能添加这个新的瓷砖片段?
弹簧thymeleaf-tiles.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- thymeleaf view resolvers with tiles integration -->
<bean id="tilesConfigurer"
class="org.thymeleaf.extras.tiles2.spring4.web.configurer.ThymeleafTilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles/tiles.xml</value>
</list>
</property>
</bean>
<!-- template resolver -->
<bean id="templateResolver"
class="org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver">
<property name="prefix" value="/WEB-INF/tiles/" />
<property name="suffix" value=".html" />
<property name="templateMode" value="HTML5" />
<property name="characterEncoding" value="utf-8" />
<property name="cacheable" value="false" />
</bean>
<!-- template engine -->
<bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine">
<property name="templateResolver" ref="templateResolver" />
<property name="additionalDialects">
<set>
<bean id="tilesDialect" class="org.thymeleaf.extras.tiles2.dialect.TilesDialect" />
</set>
</property>
</bean>
<!-- tiles view resolver -->
<bean id="tilesViewResolver" class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
<property name="viewClass"
value="org.thymeleaf.extras.tiles2.spring4.web.view.ThymeleafTilesView" />
<property name="templateEngine" ref="templateEngine" />
<property name="characterEncoding" value="utf-8" />
<property name="order" value="1" />
</bean>
</beans>
tiles.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN" "http://tiles.apache.org/dtds/tiles-config_2_1.dtd">
<tiles-definitions>
<!-- index -->
<definition name="login" template="templates/login">
<put-attribute name="head" value="fragments/head :: login_head" />
<put-attribute name="content" value="content/login :: content" />
<put-attribute name="privacy_policy" value="fragments/privacy_policy :: privacy_policy" />
<put-attribute name="scripts" value="fragments/scripts :: loginScripts" />
</definition>
<!-- user -->
<definition name="dashboard" template="templates/dashboard">
<put-attribute name="head" value="fragments/head :: dashboard_head" />
<put-attribute name="header" value="fragments/header :: header" />
<put-attribute name="sidebar" value="fragments/sidebar :: sidebar" />
<put-attribute name="footer" value="fragments/footer :: footer" />
<put-attribute name="content" value="content/dashboard :: content" />
<put-attribute name="privacy_policy" value="fragments/privacy_policy :: privacy_policy" />
<put-attribute name="scripts" value="fragments/scripts :: dashboardScripts" />
</definition>
<definition name="profile" extends="dashboard">
<put-attribute name="content" value="content/profile :: content" />
</definition>
<definition name="assets" extends="dashboard">
<put-attribute name="content" value="content/assets :: content" />
</definition>
</tiles-definitions>
login.html(模板)
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:tiles="http://www.thymeleaf.org">
<th:block tiles:include="head" th:remove="tag" />
<body>
<!-- html -->
<div id="page">
<th:block tiles:include="content" th:remove="tag" />
<th:block tiles:inlcude="privacy_policy" th:remove="tag" />
<th:block tiles:include="scripts" th:remove="tag" />
</div>
</body>
</html>
privacy_policy.html(新片段)
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:tiles="http://www.thymeleaf.org">
<body>
<th:block tiles:fragment="privacy_policy" th:remove="tag">
<div class="jumbotron">ASDFASDFASDF</div>
<h1>ASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDF</h1>
</th:block>
</body>
</html>
修改
我可以通过在拼贴定义中拼写错误属性来强制拼贴出错。
...
<definition name="login" template="templates/login">
<put-attribute name="head" value="fragments/head :: login_MISSPELLED" />
...
但如果我对新片段进行更改
,则没有错误...
<definition name="login" template="templates/login">
<put-attribute name="privacy_policy" value="fragments/privacy_policy :: privacy_MISSPELLED" />
...
答案 0 :(得分:0)
这是一个错字哈哈。哇,这真是太糟糕了。这是纠正。应该注意的是,没有html验证,甚至是我的百里香自然插件的验证,都将此视为一个问题。我自己的眼睛正好掩盖在它上面:\
login.html(模板)
...
<th:block tiles:include="privacy_policy" th:remove="tag" />
...