![thymeleaf系列二簡單表達(dá)式變量消息literals文本算術(shù)比較和條件表達(dá)式_第1頁](http://file2.renrendoc.com/fileroot_temp3/2021-11/25/75a5fd68-9f26-4186-bc95-256e016146e3/75a5fd68-9f26-4186-bc95-256e016146e31.gif)
![thymeleaf系列二簡單表達(dá)式變量消息literals文本算術(shù)比較和條件表達(dá)式_第2頁](http://file2.renrendoc.com/fileroot_temp3/2021-11/25/75a5fd68-9f26-4186-bc95-256e016146e3/75a5fd68-9f26-4186-bc95-256e016146e32.gif)
![thymeleaf系列二簡單表達(dá)式變量消息literals文本算術(shù)比較和條件表達(dá)式_第3頁](http://file2.renrendoc.com/fileroot_temp3/2021-11/25/75a5fd68-9f26-4186-bc95-256e016146e3/75a5fd68-9f26-4186-bc95-256e016146e33.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、thymeleaf 系列二簡單表達(dá)式變量消息 literals 文本算術(shù)比較和條件表達(dá)式1. 概述本節(jié)主要介紹 thymeleaf 的語法:簡單表達(dá)式。包括以下內(nèi)容:- 變量表達(dá)式: Variable Expressions- 消息表達(dá)式: Message Expressions- Literals- 文本操作符:Text operations- 算術(shù)表達(dá)式: Arithmetic operations- 比較操作符: Comparisons and equality- 條件操作符: Conditional operators2. 例子2.1 公共類Userpublic class User
2、private String name;private boolean isAdmin;private String other;private int age;/ set/get 略12345671234567Familypublic class Family private User father;private List childList;/ set/get 略1234512345ExpressionsCtl : Control 類此類初始化測試類,當(dāng)訪問此URL ,并轉(zhuǎn)到expressions/simple.html 。ControllerRequestMapping("/
3、expressions")public class ExpressionsCtl /* 簡單表達(dá)式*/RequestMapping("/simple")public String simpleExpressions(ModelMap map)/ 變量表達(dá)式: Variable Expressions User user = new User("simple_name"); user.setAge(new Random().nextInt(100); map.put("user", user);return "exp
4、ressions/simple".12345678910111213141516171234567891011121314151617下面的代碼都在此simple.html 頁面中。2.2 變量表達(dá)式 (Variable Expressions)實現(xiàn)功能:簡單的表達(dá)式變量值和字符串拼接=變量表達(dá)式 (Variable Expressions)=$ -> 'The name of the user is ' + $ -> 123456123456輸出 : “ >”的左邊是語法,右邊是對應(yīng)的輸出=變量表達(dá)式 (Vari
5、able Expressions)=$ -> simple_name'The name of the user is ' + $ -> The name of the user is simple_name 123412342.3 消息表達(dá)式:Message Expressions實現(xiàn)功能:直接從屬性文件中獲取值從屬性文件中獲取值,并替換占位符#home.welcome ->Welcome to our grocery store!#home.welcome.replace($) ->12345612
6、3456輸出 : “ >”的左邊是語法,右邊是對應(yīng)的輸出=消息表達(dá)式: Message Expressions= #home.welcome -> welcome thymeleaf #home.welcome.replace($) -> welcomethymeleaf, simple_name! 1231232.4 Literals實現(xiàn)功能:文本Text literals數(shù)字Number literals布爾值Null 值= Literals=Now you are looking at a template file. 僅僅輸出數(shù)字 th:text=&
7、quot;2013" -> 1492.數(shù)字計算th:text="2013 + 2" -> 1494.$user.isAdmin() = false ->false$user.other = null->null1234567891011121314151612345678910111213141516輸出 : “ >”的左邊是語法,右邊是對應(yīng)的輸出= Literals=Now you are looking at a working web application.僅僅輸出數(shù)字th:text="2013" ->
8、; 2013.數(shù)字計算th:text="2013 + 2" -> 2015.$user.isAdmin() = false -> false$user.other = null -> null 1234561234562.5 文本操作符:Text operations實現(xiàn)功能:+:字符串拼接字體串簡化字符中拼接操作:Literal substitutions (使用” |”包圍字符串,不需要對字符串使用”)'The name of the user is ' + $ + '_' + $user.age -&
9、gt;|Welcome to our application, $!| ->等價于這條語句:'Welcome to our application, ' + $ + '!' ->12345671234567輸出 : “ >”的左邊是語法,右邊是對應(yīng)的輸出= 文本操作符: Text operations: ='The name of the user is ' + $ + '_' + $user.age -> The name of the user is
10、 simple_name_52|Welcome to our application, $!| -> Welcome to our application, simple_name!等價于這條語句:'Welcome to our application, ' + $ + '!' -> Welcome to our application, simple_name! 12345123452.6 算術(shù)表達(dá)式: Arithmetic operations 實現(xiàn)功能:二進(jìn)制運算符 : Binary operators: +
11、, -, *, /, %Boolean operations: true,false, !, notBinary operators: and, or$user.age % 2 = 0 ->true ->!($user.age % 2 = 0 -> ($user.age % 2 = 0) and true ->1234567891012345678910輸出 : “ >”的左邊是語法,右邊是對應(yīng)的輸出= 算術(shù)表達(dá)式: Arithmetic operations = $user.age % 2 = 0 -> truetrue -> true!($user
12、.age % 2 = 0 -> false($user.age % 2 = 0) and true -> true1234512345 2.7 比較操作符: Comparisons and equality實現(xiàn)功能:比較符號 Comparators: >, =,Equality operators: =, != (eq, ne)= 比較操作符: Comparisons and equality = , =,$user.age > 18 ->大人$user.age != 18 ->大人_no_equality123456123456輸出 : “ >
13、;”的左邊是語法,右邊是對應(yīng)的輸出=比較操作符: Comparisonsand equality =$user.age > 18 ->大人$user.age != 18 -> 大人 _no_equality 123123 2.8 條件操作符: Conditional operators實現(xiàn)功能:If-then: (if) ? (then)If-then-else: (if) ? (then) : (else)如果 null 值,則使用? :后面的值 : Default: (value) ?:(defaultvalue)$user.age%2=0 ? 'even' ->$user.age%2=0 ? 'even' :'odd' ->$user.age ?:'18' ->12345671234567輸出 :
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 現(xiàn)代辦公模式下的軟件盜版防范策略研究
- 國慶節(jié)活動團(tuán)購活動方案
- 生態(tài)旅游規(guī)劃的核心策略案例研究報告
- Unit 2 My family(Period 4)(說課稿)-2024-2025學(xué)年人教大同版(2024)英語三年級上冊
- 12 盤古開天地 (說課稿)-2024-2025學(xué)年統(tǒng)編版語文四年級上冊
- 21三黑和土地 (說課稿)-2024-2025學(xué)年六年級上冊語文統(tǒng)編版
- 14文言文二則《兩小兒辯日》(說課稿)-2023-2024學(xué)年統(tǒng)編版語文六年級下冊
- 2024年五年級數(shù)學(xué)上冊 5 簡易方程第16課時 實際問題與方程(5)配套說課稿 新人教版
- 2024-2025學(xué)年高中物理 第10章 熱力學(xué)定律 4 熱力學(xué)第二定律說課稿1 新人教版選修3-3
- 2025道路綠化養(yǎng)護(hù)委托合同
- 阿基米德課件
- 2024年步步高高考英語大一輪復(fù)習(xí)(新人教版)基礎(chǔ)知識默寫本必修第一冊含答案
- 盤錦市重點中學(xué)2024年中考英語全真模擬試卷含答案
- 2024年《幼兒教師職業(yè)道德》教案
- 平安產(chǎn)險湖南省商業(yè)性雞蛋價格指數(shù)保險條款
- 石家莊市第四十中學(xué)2021-2022學(xué)年七年級上學(xué)期期末考試數(shù)學(xué)試題
- 《共演戰(zhàn)略》分析工具
- 揚州市古樹名木匯編
- 提高臥床患者踝泵運動的執(zhí)行率
- 裝配式建筑預(yù)制構(gòu)件運輸與堆放-預(yù)制構(gòu)件運輸基本要求
- Ar-CO2 混合氣安全技術(shù)說明書
評論
0/150
提交評論