Freemarker条件判断
生活随笔
收集整理的這篇文章主要介紹了
Freemarker条件判断
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
判斷語法
<#if target??>xxxx </#if>比如
判斷索引,是否為偶數
數據集
//6.創建一個數據集,可以是pojo也可以是map,推薦使用map Map data = new HashMap<>(); data.put("hello", "hello freemarker"); Student student = new Student(1, "小米", 11, "北京昌平回龍觀"); data.put("student", student); List<Student> stuList = new ArrayList<>(); stuList.add(new Student(1, "小米", 11, "北京昌平回龍觀")); stuList.add(new Student(2, "小米2", 12, "北京昌平回龍觀")); stuList.add(new Student(3, "小米3", 13, "北京昌平回龍觀")); stuList.add(new Student(4, "小米4", 14, "北京昌平回龍觀")); stuList.add(new Student(5, "小米5", 15, "北京昌平回龍觀")); stuList.add(new Student(6, "小米6", 16, "北京昌平回龍觀")); stuList.add(new Student(7, "小米7", 17, "北京昌平回龍觀")); data.put("stuList", stuList);模板
<html> <head><title>測試頁面</title> </head> <body>學生列表:<br><table border="1"><tr><th>序號</th><th>學號</th><th>姓名</th><th>年齡</th><th>家庭住址</th></tr><#list stuList as stu><#if stu_index%2==0><tr bgcolor="red"><#else><tr bgcolor="blue"></#if><td>${stu_index}</td><td>${stu.id}</td><td>${stu.name}</td><td>${stu.age}</td><td>${stu.address}</td></tr></#list></table><br>使用if判斷null值:<#if val??>val是有值的<#else>val值為null</#if> </body> </html>總結
以上是生活随笔為你收集整理的Freemarker条件判断的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Freemarker循环遍历
- 下一篇: Freemarker日期时间类型