<h2>遍历</h2>
<textarea class="form-control" cols="100" rows="10">
<#list ruleList as vi>
Code: ${vi.code}, Name: ${vi.name} <br>
</#list>
</textarea>
<br>
<h2>嵌套遍历</h2>
<textarea class="form-control" cols="100" rows="10">
<#list configurationList as vi>
<h2>${vi.tbIndex}</h2>
<ul>
<#list vi.fieldList as vj>
<li>${vj.name} - ${vj.remark}</li>
</#list>
</ul>
</#list>
</textarea>
<h2>赋值指令</h2>
<textarea class="form-control" cols="100" rows="10">
<#assign name = "Freemarker">
</textarea>
<br>
<h2>直接显示文本</h2>
<textarea class="form-control" cols="100" rows="10">
Hello, ${name}!
</textarea>
<br>
<h2>遍历</h2>
<textarea class="form-control" cols="100" rows="10">
<#assign users = [{"name": "Alice", "age": 25}, {"name": "Bob", "age": 30}]>
<#list users as user>
Name: ${user.name}, Age: ${user.age}
</#list>
</textarea>
<br>
<h2>嵌套遍历</h2>
<textarea class="form-control" cols="100" rows="10">
<#assign classes = [
{"name": "班级A", "students": ["学生1", "学生2", "学生3"]},
{"name": "班级B", "students": ["学生4", "学生5"]},
{"name": "班级C", "students": ["学生6", "学生7", "学生8", "学生9"]}
]>
<#list classes as class>
<h2>${class.name}</h2>
<ul>
<#list class.students as student>
<li>${student}</li>
</#list>
</ul>
</#list>
</textarea>
<br>
<h2>判断数据不为空,再执行遍历 (如果序列不存在,直接遍历会报错)</h2>
<textarea class="form-control" cols="100" rows="10">
<#if users2??>
<#list users2 as user>
${user}
</#list>
</#if>
</textarea>
<br>
<h2>当序列没有数据项时,使用默认信息</h2>
<textarea class="form-control" cols="100" rows="10">
<#assign users3 = []>
<#list users3 as user>
${user} |
<#else >
用户数据不存在!
</#list>
</textarea>
<br>
<h2>判断数据是否存在</h2>
<textarea class="form-control" cols="100" rows="10">
<#assign list="">
<#if list??>
数据存在
<#else >
数据不存在
</#if>
<br>
<#if list2??>
数据存在
<#else >
数据不存在
</#if>
</textarea>
<br>
<h2>遍历时,判断是否是第一个和最后一个</h2>
<textarea class="form-control" cols="100" rows="10">
<#assign userLast = [{"name": "1Alice", "age": 25}, {"name": "2Bob", "age": 30}, {"name": "3Lilei", "age": 30}, {"name": "4June", "age": 30}]>
<#list userLast as user>
Name: ${user.name}, Age: ${user.age}
<#if user_index = 0>
<span>(第一个元素)</span>
</#if>
<#if user_has_next>
<#else>
<span>(最后一个)</span>
</#if>
<#if !user_has_next>
(最后一个元素)
</#if>
<#if !user?has_next>
<!-- 当前元素是最后一个元素 -->
(这是最后一个元素)
</#if>
</#list>
</textarea>
<br>
<h2>条件判断</h2>
<textarea class="form-control" cols="100" rows="10">
<#assign age = 15>
<#if age gte 18>
You are an adult.
<#else>
You are a minor.
</#if>
</textarea>
<br>
<h2>Switch 判断</h2>
<textarea class="form-control" cols="100" rows="10">
<#assign day = "Friday">
<#switch day>
<#case "Monday">
Start of the week!
<#case "Friday">
Almost weekend!
<#default>
Just another day.
</#switch>
</textarea>
<br>
<h2>判断字符串中是否包含子字符串</h2>
<textarea class="form-control" cols="100" rows="10">
<#assign str = "Hello, World!">
<#if str?contains("World")>
The string contains "World".
<#else>
The string does not contain "World".
</#if>
</textarea>
<br>
<h2>判断Set中是否包含某个键</h2>
<textarea class="form-control" cols="100" rows="10">
<#assign sample = ["A","B","C","D"]>
<#assign str1 = "E">
<#assign str2 = "A">
<#if sample?seq_contains("A")>
The set contains "A".
<#else>
The set does not contain "A".
</#if>
${sample?seq_contains(str1)?string("yes","no")} <!-- no -->
${sample?seq_contains(str2)?string("yes","no")} <!-- yes -->
</textarea>
<br>
<h2>判断Map中是否包含某个键</h2>
<textarea class="form-control" cols="100" rows="10">
<#assign myMap = {"key1": "value1", "key2": "value2"}>
<#if myMap?keys?seq_contains("key1")>
The map contains the key "key1"
<#else>
The map does not contain the key "key1"
</#if>
</textarea>
<br>
<h2>使用自定义方法</h2>
<textarea class="form-control" cols="100" rows="10">
${func.random(32)}
</textarea>