[英]GET request processed by wrong DispatcherServlet (spring, tiles2, thymeleaf)
[英]Spring MVC, Tiles2, ThymeLeaf and Natural Templating
在將Tiles2用作模板引擎時,如何有效地使用ThymeLeaf自然模板。 我有一個簡單的圖塊定義:
<tiles-definitions>
<definition name="/**;layout:*" template="templates/{2}_layout">
<put-attribute name="header" value="templates/header"/>
<put-attribute name="content" value="/{1}"/>
<put-attribute name="footer" value="templates/footer"/>
</definition>
...
</tiles-definitions>
和我的布局
<html lang="pl" xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.springframework.org/security/tags"
xmlns:tiles="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="stylesheet" type="text/css" th:href="@{~/css/bootstrap.min.css}" href="../../../css/bootstrap.min.css"/>
... and many others
</head>
<body>
<div class="top-header" tiles:include="header">Header to include</div>
<div class="container-main" tiles:include="content">Content to include</div>
<div tiles:include="footer">Footer to include</div>
</body>
和一個簡單的content.html模板
<div id="main" class="panel panel-main">
<div id="contents" class="panel-body">
bla bla bla
</div>
</div>
我遇到的問題是:如果我嘗試在本地檢查content.html,那么它將看起來不應該,因為我沒有定義具有CSS和JS定義的<html>
和<head>
。
如果我添加了<html><head>
標記,那么在運行時,結果頁面上會有許多html定義(來自頁眉/內容/頁腳模板)!
對我來說,一個完美的解決方案是:我想利用<html><head>
標簽定義content.html,充分利用自然模板和語法檢查的優勢,然后以某種方式包括此文件,但不包含這些標簽(僅body或div ) 可能嗎?
您可以使用
<!-- /* -->
和
<!--*/-->.
這些注釋標簽中的每個標簽在運行時都會被忽略(它們不會顯示在實際頁面中)。
<!--/*-->
<html>
<head>
<title>Test</title>
</head>
<body>
<!--*/-->
<div>...</div>
<!--/*-->
<body>
</html>
<!--*/-->
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.