簡體   English   中英

spring-mvc應用程序的模板和布局

[英]template and layout for spring-mvc application

我正在使用帶有Spring MVC框架的jee。 我想制作一個包含修復菜單和隨URI而變化的內容的模板。

我想為模板執行相同的代碼,假設模板中的數據庫要加載一些內容。 因此,我希望在加載模板並初始化所有動態內容的情況下執行Java方法。

最佳選擇是什么? Thymeleaf視圖引擎可以做到這一點嗎? 還有其他選擇嗎?

謝謝

好吧,如果我正確理解了,我認為Thymeleaf是最好的選擇,您可以像這樣創建一個模板頁面:

template.html:

<!DOCTYPE html>
  <html xmlns:th="http://www.thymeleaf.org"
  xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">

/* Here you put your CSS and JS files and so on.. */

<body>
  <header> ... </header>


    /* Here you can put anything you want beacause this template will be
 always executed */


  <section th:fragment="content></section>

  <footer> ... </footer>
</body>

您可以為所有HTML頁面制作自己的頁眉和頁腳。

然后,您可以使用此模板創建HTML頁面。 例如,如果您選擇實現主頁,則可以這樣操作

home.html:

<!DOCTYPE html>
  <html xmlns:th="http://www.thymeleaf.org"
  xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
  layout:decorator="template">

 /* Here you have your CSS, JS files.. and body tag */

 <div layout:fragment="content"> ... </div>

您要放入div中的所有內容都將包含在模板頁面的section標簽中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM