2015-05-26 52 views
1

晚上好, 我創建基於Spring MVC的後端和Twitter的引導前端的一個項目。 我想爲我的重複頁面(頁眉和頁腳固定的所有網頁)只是我想避免在所有頁面重複的代碼(因爲它是不好的做法,可能會導致錯誤)創建一個模板。有沒有辦法集中什麼?我想到了jsp(一種用於頁眉和頁腳)並在各種視圖中回顧。有沒有辦法做到這一點?或者有更好的選擇?Spring MVC和Twitter的引導模板

感謝

回答

2

您可以使用JSP ...有include標籤,你可以使用這樣的:

<%@ include file="/views/templates/header.jsp" %> 
// Rest of the content 
<%@ include file="/views/templates/footer.jsp" %> 

或者你可以使用一個框架模板,像瓷磚或Freemarker的。

Spring MVC的使用Tiles:http://java.dzone.com/articles/spring-mvc-tiles-3-integration

使用瓷磚,模板頁面:

<body> 
<div class="container" style="border: #C1C1C1 solid 1px; border-radius:10px;"> 
    <!-- Header --> 
    <tiles:insertAttribute name="header" /> 
    <!-- Body Page --> 
    <div class="span-19 last"> 
     <tiles:insertAttribute name="body" /> 
    </div> 
    <!-- Footer Page --> 
    <tiles:insertAttribute name="footer" /> 
</div> 
</body> 

,你可以改變動態 「身體」 磚屬性。

+1

謝謝,這正是我一直在尋找! – Matteo