Freemarker条件判断
7875 ワード
判断文法
<#if target??>
xxxx
#if>
例えばインデックスが偶数かどうかを判断する
<#if student_index % 2 == 0>
xxxx
<#else>
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>