亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 學院 > 開發設計 > 正文

Thymeleaf基本知識

2019-11-14 22:11:52
字體:
來源:轉載
供稿:網友
Thymeleaf基本知識

Thymeleaf是個xml/XHTML/HTML5模板引擎,可以用于Web與非Web應用。

Thymeleaf的主要目標在于提供一種可被瀏覽器正確顯示的、格式良好的模板創建方式,因此也可以用作靜態建模。你可以使用它創建經過驗證的XML與HTML模板。相對于編寫邏輯或代碼,開發者只需將標簽屬性添加到模板中即可。接下來,這些標簽屬性就會在DOM(文檔對象模型)上執行預先制定好的邏輯。Thymeleaf的可擴展性也非常棒。你可以使用它定義自己的模板屬性集合,這樣就可以計算自定義表達式并使用自定義邏輯。這意味著Thymeleaf還可以作為模板引擎框架。

Thymeleaf的模板還可以用作工作原型,Thymeleaf會在運行期替換掉靜態值。例如下面的html文件,當作為靜態文件時,PRoduct name顯示為Red Chair,當運行在容器中并提供product這個對象時,product name的值會自動替換為product.description對應的值。

1.bean值替換
 1 <!DOCTYPE html> 2 <html xmlns:th="http://www.thymeleaf.org"> 3     <head> 4         <title>Thymeleaf tutorial: exercise 2</title> 5         <link rel="stylesheet" href="../../../CSS/main-static.css" th:href="@{/css/main.css}" /> 6         <meta charset="utf-8" /> 7     </head> 8     <body> 9         <h1>Thymeleaf tutorial - Answer for exercise 1: bean values</h1>10         <h2>Product information</h2>11         <dl>12             <dt>Product name</dt>13             <dd th:text="${product.description}">Red Chair</dd>14 15             <dt>Product price</dt>16             <dd th:text="${product.price}">350</dd>17 18             <dt>Product available from</dt>19             <dd th:text="${product.availableFrom}">2014-12-01</dd>20         </dl>21     </body>22 </html>
2.簡單數據轉換(數字,日期)
 1 <!DOCTYPE html> 2 <html xmlns:th="http://www.thymeleaf.org"> 3     <head> 4         <title>Thymeleaf tutorial: exercise 2</title> 5         <link rel="stylesheet" href="../../../css/main-static.css" th:href="@{/css/main.css}" /> 6         <meta charset="utf-8" /> 7     </head> 8     <body> 9         <h1>Thymeleaf tutorial - Answer for exercise 2: bean values</h1>10         <h2>Product information</h2>11         <dl>12             <dt>Product name</dt>13             <dd th:text="${product.description}">red Chair</dd>14 15             <dt>Product price</dt>16             <dd th:text="${#numbers.formatDecimal(product.price, 1, 2)}">180</dd>17 18             <dt>Product available from</dt>19             <dd th:text="${#dates.format(product.availableFrom, 'yyyy-MM-dd')}">2014-12-01</dd>20         </dl>21     </body>22 </html>
3.字符串拼接
 1 <!DOCTYPE html> 2 <html xmlns:th="http://www.thymeleaf.org"> 3     <head> 4         <title>Thymeleaf tutorial: exercise 3</title> 5         <link rel="stylesheet" href="../../../css/main-static.css" th:href="@{/css/main.css}" /> 6         <meta charset="utf-8" /> 7     </head> 8     <body> 9         <h1>Thymeleaf tutorial - Answer for exercise 3: string concatenation</h1>10         <h2>Product information</h2>11         <dl>12             <dt>Product price</dt>13             <dd th:text="${'$'+product.price}">235</dd>14         </dl>15     </body>16 </html>
4.國際化
 1 <!DOCTYPE html> 2 <html xmlns:th="http://www.thymeleaf.org"> 3     <head> 4         <title th:text="#{tutorial.exercise4}">Thymeleaf tutorial: exercise 4</title> 5         <link rel="stylesheet" href="../../../css/main-static.css" th:href="@{/css/main.css}" /> 6         <meta charset="utf-8" /> 7     </head> 8     <body> 9         <h1 th:text="#{tutorial.exercise4}">Thymeleaf tutorial - Solution for exercise 4: internationalization</h1>10         <h2 th:text="#{product.info}">Product information</h2>11         <dl>12             <dt th:text="#{product.name}">Product name</dt>13             <dd th:text="${product.description}">Red chair</dd>14 15             <dt th:text="#{product.price}">Product price</dt>16             <dd th:text="${#numbers.formatDecimal(product.price, 1, 2)}">350</dd>17 18             <dt th:text="#{product.available}">Product available from</dt>19             <dd th:text="${#dates.format(product.availableFrom, 'dd-MMM-yyyy')}">28-Jun-2013</dd>20         </dl>21     </body>22 </html>

此時html需要相應的配置文件。例如如下配置文件:

en:

tutorial.exercise4=Thymeleaf tutorial - exercise 4: internationalizationproduct.info=Product informationproduct.name=Product nameproduct.price=Product priceproduct.available=Product available fromback=Back

fr

tutorial.exercise4=Tutorial De Thymeleaf - exercice 4: l'internationalisationproduct.info=Information du produitproduct.name=Nom du produitproduct.price=Prix du produitproduct.available=Produit disponible depuisback=Revenir
5.轉義和非轉義文本
 1 <!DOCTYPE html> 2 <html xmlns:th="http://www.thymeleaf.org"> 3     <head> 4         <title>Thymeleaf tutorial: exercise 5</title> 5         <link rel="stylesheet" href="../../../css/main-static.css" th:href="@{/css/main.css}" /> 6         <meta charset="utf-8" /> 7     </head> 8     <body> 9         <h1>Thymeleaf tutorial - Solution for exercise 5: escaped and unescaped text</h1>10         <div th:text="${html}">11             Some escaped text12         </div>13         <div th:utext="${html}">14             Some unescaped text15         </div>16     </body>17 </html>

上述兩個div分別生成的html代碼為

<div>This is an &lt;em&gt;HTML&lt;/em&gt; text. &lt;b&gt;Enjoy yourself!&lt;/b&gt;</div><div>This is an <em>HTML</em> text. <b>Enjoy yourself!</b></div>
6.迭代
 1 <!DOCTYPE html> 2 <html xmlns:th="http://www.thymeleaf.org"> 3     <head> 4         <title>Thymeleaf tutorial: exercise 6</title> 5         <link rel="stylesheet" href="../../../css/main-static.css" th:href="@{/css/main.css}" /> 6         <meta charset="utf-8" /> 7     </head> 8     <body> 9         <h1>Thymeleaf tutorial - Answer for exercise 6: iteration</h1>10         <h2>Product list</h2>11         <table>12             <thead>13                 <tr>14                     <th>Description</th>15                     <th>Price</th>16                     <th>Available from</th>17                 </tr>18             </thead>19             <tbody th:remove="all-but-first">20                 <tr th:each="product:${productList}">21                     <td th:text="${product.description}">Red Chair</td>22                     <td th:text="${'$' + #numbers.formatDecimal(product.price, 1, 2)}">$123</td>23                     <td th:text="${#dates.format(product.availableFrom, 'yyyy-MM-dd')}">2014-12-01</td>24                 </tr>25                 <tr>26                     <td>White table</td>27                     <td>$200</td>28                     <td>15-Jul-2013</td>29                 </tr>30                 <tr>31                     <td>Reb table</td>32                     <td>$200</td>33                     <td>15-Jul-2013</td>34                 </tr>35                 <tr>36                     <td>Blue table</td>37                     <td>$200</td>38                     <td>15-Jul-2013</td>39                 </tr>40             </tbody>41         </table>42     </body>43 </html>
7.迭代統計
 1 <!DOCTYPE html> 2 <html xmlns:th="http://www.thymeleaf.org"> 3     <head> 4         <title>Thymeleaf tutorial: exercise 7</title> 5         <link rel="stylesheet" href="../../../css/main-static.css" th:href="@{/css/main.css}" /> 6         <meta charset="utf-8" /> 7     </head> 8     <body> 9         <h1>Thymeleaf tutorial - Solution for exercise 7: iteration stats</h1>10         <h2>Product list</h2>11         <table>12             <thead>13                 <tr>14                     <th>Index</th>15                     <th>Description</th>16                     <th>Price</th>17                     <th>Available from</th>18                 </tr>19             </thead>20             <tbody th:remove="all-but-first">21                 <tr th:each="product : ${productList}">22                     <td th:text="${productStat.count}">1</td>23                     <td th:text="${product.description}">Red chair</td>24                     <td th:text="${'$' + #numbers.formatDecimal(product.price, 1, 2)}">$350</td>25                     <td th:text="${#dates.format(product.availableFrom, 'dd-MMM-yyyy')}">28-Jun-2013</td>26                 </tr>27                 <tr>28                     <td>2</td>29                     <td>White table</td>30                     <td>$200</td>31                     <td>15-Jul-2013</td>32                 </tr>33                 <tr>34                     <td>3</td>35                     <td>Reb table</td>36                     <td>$200</td>37                     <td>15-Jul-2013</td>38                 </tr>39                 <tr>40                     <td>4</td>41                     <td>Blue table</td>42                     <td>$200</td>43                     <td>15-Jul-2013</td>44                 </tr>45             </tbody>46         </table>47     </body>48 </html>
8.條件判斷
 1 <!DOCTYPE html> 2 <html xmlns:th="http://www.thymeleaf.org"> 3     <head> 4         <title>Thymeleaf tutorial: exercise 8</title> 5         <link rel="stylesheet" href="../../../css/main-static.css" th:href="@{/css/main.css}" /> 6         <meta charset="utf-8" /> 7     </head> 8     <body> 9         <h1>Thymeleaf tutorial - Answer for exercise 8: conditions</h1>10         <h2>Product list</h2>11         <table>12             <thead>13                 <tr>14                     <th>Description</th>15                     <th>Price</th>16                     <th>Available from</th>17                     <th></th>18                 </tr>19             </thead>20             <tbody>21                 <tr th:each="product : ${productList}">22                     <td th:text="${product.description}">Red chair</td>23                     <td th:text="${'$' + #numbers.formatDecimal(product.price, 1, 2)}">$350</td>24                     <td th:text="${#dates.format(product.availableFrom, 'dd-MMM-yyyy')}">28-Jun-2013</td>25                     <td>26                         <span th:if="${product.price lt 100}" class="offer">Special offer!</span>27                     </td>28                 </tr>29             </tbody>30         </table>31     </body>32 </html>
9.更多條件判斷
 1 <!DOCTYPE html> 2 <html xmlns:th="http://www.thymeleaf.org"> 3     <head> 4         <title>Thymeleaf tutorial: exercise 9</title> 5         <link rel="stylesheet" href="../../../css/main-static.css" th:href="@{/css/main.css}" /> 6         <meta charset="utf-8" /> 7     </head> 8     <body> 9         <h1>Thymeleaf tutorial - Answer for exercise 9: more on conditions</h1>10         <h2>Customer list</h2>11         <table>12             <thead>13                 <tr>14                     <th>First name</th>15                     <th>Last name</th>16                     <th>Gender</th>17                     <th>Payment method</th>18                     <th>Balance</th>19                 </tr>20             </thead>21             <tbody th:remove="all-but-first">22                 <tr th:each="customer : ${customerList}">23                     <td th:text="${customer.firstName}">Peter</td>24                     <td th:text="${customer.lastName}">Jackson</td>25                     <!-- 26                        Use th:switch for selecting content based on ${customer.gender}.27                        As genre can be null if unknown, better use ${customer.gender?.name()}28                        for obtaining its name.29                     -->30                     <td th:switch="${customer.gender?.name()}">31                         <img th:case="'MALE'" src="../../../images/male.png" th:src="@{/images/male.png}" alt="Male" /> <!-- Use "/images/male.png" image -->32                         <img th:case="'FEMALE'" src="../../../images/female.png" th:src="@{/images/female.png}" alt="Female" /> <!-- Use "/images/female.png" image -->33                         <span th:case="*">Unknown</span>34                     </td>35                     <td>36                         <span th:text="${customer.paymentMethod.description}">Direct debit</span>37                         <!-- Show next message only when paymentMethod is not CREDIT_CARD -->38                         <span th:unless="${customer.paymentMethod.name() == 'CREDIT_CARD'}" class="warn">39                             Payment must be done in the next 4 days40                         </span>41                     </td>42                     <!-- Add class="enhanced" when balance is greater than 10000 -->43                     <td th:class="${customer.balance gt 10000} ? 'enhanced'" th:text="${customer.balance}">350</td>44                 </tr>45                 <tr>46                     <td>Mary</td>47                     <td>Johanson</td>48                     <td><img src="../../../images/female.png" /></td>49                     <td><span>Credit card</span></td>50                     <td>5000</td>51                 </tr>52                 <tr>53                     <td>Robert</td>54                     <td>Allen</td>55                     <td><img src="../../../images/male.png" /></td>56                     <td>57                         <span>Credit card</span>58                         <span class="warn">Payment must be done in the next 4 days</span>59                     </td>60                     <td class="enhanced">50000</td>61                 </tr>62             </tbody>63         </table>64     </body>65 </html>
10.Spring表達式語言
 1 <!DOCTYPE html> 2 <html xmlns:th="http://www.thymeleaf.org"> 3     <head> 4         <title>Thymeleaf tutorial: exercise 10</title> 5         <link rel="stylesheet" href="../../../css/main-static.css" th:href="@{/css/main.css}" /> 6         <meta charset="utf-8" /> 7     </head> 8     <body> 9         <h1>Thymeleaf tutorial - Solution for exercise 10: Spring Expression language</h1>10   11         <h2>Arithmetic expressions</h2>12         <p class="label">Four multiplied by minus six multiplied by minus two module seven:</p>13         <p class="answer" th:text="${4 * -6 * -2 % 7}">123</p>14  15         <h2>Object navigation</h2>16         <p class="label">Description field of paymentMethod field of the third element of customerList bean:</p>17         <p class="answer" th:text="${customerList[2].paymentMethod.description}">Credit card</p>18  19         <h2>Object instantiation</h2>20         <p class="label">Current time milliseconds:</p>21         <p class="answer" th:text="${new java.util.Date().getTime()}">22-Jun-2013</p>22         23         <h2>T Operator</h2>24         <p class="label">Random number:</p>25         <p class="answer" th:text="${T(java.lang.Math).random()}">123456</p>26     </body>27 </html>
11.超鏈接
 1 <!DOCTYPE html> 2 <html xmlns:th="http://www.thymeleaf.org"> 3     <head> 4         <title>Thymeleaf tutorial: exercise 11</title> 5         <link rel="stylesheet" href="../../../css/main-static.css" th:href="@{/css/main.css}" /> 6         <meta charset="utf-8" /> 7     </head> 8     <body> 9         <h1>Thymeleaf tutorial - Answer for exercise 11: links</h1>10         <h2>Product actions</h2>11         <ul>12             <li><a href="#" th:href="@{/exercise11/product.html(action='view')}">View product</a></li>13             <li><a href="#" th:href="@{/exercise11/product.html(action='edit')}">Edit product</a></li>14         </ul>15     </body>16 </html>
12.表單
 1 <!DOCTYPE html> 2 <html xmlns:th="http://www.thymeleaf.org"> 3     <head> 4         <title>Thymeleaf tutorial: exercise 12</title> 5         <link rel="stylesheet" href="../../../css/main-static.css" th:href="@{/css/main.css}" /> 6         <meta charset="utf-8" /> 7     </head> 8     <body> 9         <h1>Thymeleaf tutorial - Solution for exercise 12: forms</h1>10         <h2>Customer edition</h2>11         <form action="saveCustomer.html" th:action="@{/exercise12/saveCustomer.html}" th:object="${customer}" method="post">12             <input type="hidden" th:field="*{id}" />13             14             <label for="firstName">First name:</label>15             <input type="text" th:field="*{firstName}" value="John" />16             17             <label for="lastName">Last name:</label>18             <input type="text" th:field="*{lastName}" value="Wayne" />19             20             Genre:21             <div th:each="gender : ${genders}" class="radio">22                 <input type="radio" th:value="${gender}" th:field="*{gender}" />23                 <label th:for="${#ids.prev('gender')}" th:text="${gender.description}">Male</label>24             </div>25             <div th:remove="all" class="radio">26                 <input type="radio" />27                 <label>Female</label>28             </div>29             30             <label for="paymentMethod">Payment method:</label>31             <select th:field="*{paymentMethod}" th:remove="all-but-first">32                 <option th:each="paymentMethod : ${paymentMethods}"33                         th:value="${paymentMethod}" th:text="${paymentMethod.description}">Credit card</option>34                 <option>Another payment method</option>35                 <option>Another payment method</option>36             </select>37             38             <label for="balance">Balance (dollars):</label>39             <input type="text" th:field="*{balance}" size="10" value="2500" />40             41             <input type="submit" />42         </form>43     </body>44 </html>
13.內聯
<!DOCTYPE html><html xmlns:th="http://www.thymeleaf.org">    <head>        <title>Thymeleaf tutorial: exercise 13</title>        <link rel="stylesheet" href="../../../css/main-static.css" th:href="@{/css/main.css}" />        <meta charset="utf-8" />    </head>    <body>        <h1>Thymeleaf tutorial - Solution for exercise 13: inlining</h1>        <h2>Birthday email</h2>        <form action="#" method="post">            <label for="body">Message body:</label><textarea id="body" name="body" th:inline="text">Dear [[${customerName}]],it is our sincere pleasure to congratulate your in your birthday:    Happy birthday [[${customerName}]]!!!See you soon, [[${customerName}]].Regards,    The Thymeleaf team</textarea>            <input type="submit" value="Send mail" />        </form>    </body></html>

--------------------------------------------------------------------------------------------------------------

以上資料都來自http://itutorial.thymeleaf.org/。如果對Thymeleaf有興趣,可以試試他們做的交互教程,很是好用。上面的html代碼都是來自thymeleaf的交互教程


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
性色av一区二区三区红粉影视| 精品亚洲一区二区三区| 伊人伊成久久人综合网站| 一本一本久久a久久精品牛牛影视| 在线观看91久久久久久| 日韩电影在线观看永久视频免费网站| 国产999精品视频| 国产精品免费久久久久久| 亚洲欧美在线一区| 国产成人在线亚洲欧美| 国产精品美女av| 中文字幕日韩av电影| 97超级碰碰人国产在线观看| 26uuu日韩精品一区二区| 亚洲国产99精品国自产| 日本午夜精品理论片a级appf发布| 国产成人亚洲综合青青| 97在线视频一区| 日韩精品视频在线观看网址| 日本精品视频网站| 狠狠操狠狠色综合网| 亚洲人成电影在线| 欧美激情网友自拍| 日韩精品在线电影| 欧美猛少妇色xxxxx| 91在线观看免费| 国产精品视频精品视频| 在线播放日韩av| 4k岛国日韩精品**专区| 国产成人av网址| 亚洲毛片在线免费观看| 国产精品黄页免费高清在线观看| 久久夜色精品国产| 一本色道久久88亚洲综合88| 中文字幕亚洲一区二区三区| 亚洲男人天堂九九视频| 国产精品av电影| 国外成人性视频| 51精品在线观看| 久久精品99久久久香蕉| 欧美日韩免费看| 亚洲精品国产精品自产a区红杏吧| 日韩免费不卡av| 中文字幕亚洲综合| 欧美激情精品久久久久久黑人| 久久免费视频这里只有精品| 国模精品视频一区二区三区| 欧美影院在线播放| 国产精品成人免费电影| 久久人人爽人人爽爽久久| 欧美日韩一区二区在线播放| 久久久久久国产三级电影| 午夜剧场成人观在线视频免费观看| 国产精品综合久久久| 国产精品精品视频| 国产日韩欧美综合| 日韩美女在线播放| 日韩欧美在线视频观看| 久久久久久亚洲精品中文字幕| 成人免费淫片aa视频免费| 亚洲欧美日韩一区二区三区在线| 久久精品国产欧美激情| 国产欧美久久久久久| 午夜免费久久久久| 麻豆一区二区在线观看| 久久夜精品香蕉| 亚洲理论在线a中文字幕| 国内外成人免费激情在线视频网站| 精品国产91乱高清在线观看| 亚洲精品国产综合久久| 国产精品香蕉av| 性欧美xxxx视频在线观看| 久久精品国产精品| 日韩精品中文在线观看| 亚洲全黄一级网站| 国产精品偷伦免费视频观看的| 亚洲欧洲日本专区| 91精品在线影院| 国产精品视频1区| 亚洲欧美激情另类校园| 91精品国产99久久久久久| 麻豆乱码国产一区二区三区| 国产亚洲成精品久久| 国产精品a久久久久久| 久久精品国产2020观看福利| www.久久色.com| 好吊成人免视频| 亚洲欧美在线一区二区| 成人在线国产精品| 久久综合伊人77777尤物| 国产精品色午夜在线观看| 成人精品视频久久久久| 青青在线视频一区二区三区| 姬川优奈aav一区二区| 91国产视频在线播放| 久久久久久久久久久91| 国产精品久久久91| 色妞一区二区三区| 国产一区二区欧美日韩| 亚洲电影免费观看高清完整版在线观看| 97人人模人人爽人人喊中文字| 国产精品久久久久久久一区探花| 国外日韩电影在线观看| 日韩在线免费高清视频| 欧美性猛交xxx| 91a在线视频| 国产免费亚洲高清| 国内精品久久久久伊人av| 国产女人18毛片水18精品| 色综合亚洲精品激情狠狠| 日韩中文字幕国产精品| 日韩欧美aaa| 久久天天躁狠狠躁老女人| 91视频88av| 91在线看www| 成人两性免费视频| 欧美在线视频观看| 日本一区二区不卡| 亚洲视屏在线播放| 国产精品美女久久久久久免费| 亚洲国产精品va在线看黑人| 久久国产精品久久精品| 97免费视频在线播放| 亚洲综合国产精品| 亚洲精品日韩丝袜精品| 欧美在线视频观看| 亚洲第一网站男人都懂| 一个人看的www久久| 久久频这里精品99香蕉| 热久久免费视频精品| 中文字幕亚洲欧美| 国产精品久久久| 国产91精品最新在线播放| 97在线观看视频国产| 色偷偷噜噜噜亚洲男人| 亚洲第一页自拍| 欧美国产高跟鞋裸体秀xxxhd| 亚洲免费伊人电影在线观看av| 在线免费观看羞羞视频一区二区| 日韩欧美aⅴ综合网站发布| 国产精品狠色婷| 精品久久久久久中文字幕大豆网| 亚洲情综合五月天| 精品国产一区久久久| 成人免费大片黄在线播放| 欧美日韩免费网站| 亚洲无限乱码一二三四麻| 日韩在线视频网站| 日韩av电影手机在线观看| 日韩免费在线播放| 亚洲精品98久久久久久中文字幕| 久久久久久久久久久免费| 精品欧美国产一区二区三区| 国产69久久精品成人看| 成人有码在线播放| 永久免费毛片在线播放不卡| 亚洲人成电影在线| 亚洲色图综合久久| 69久久夜色精品国产7777| www欧美xxxx| 高清欧美电影在线| 一本一本久久a久久精品牛牛影视| 色七七影院综合| 国语自产偷拍精品视频偷|