freemarker处理嵌套属性是否为空的判断
ftl page code:
1
<#escape x as x?if_exists?html>
2
3
用户名:${user?if_exists.userName}<br>
4
5
姓名:${'name'}<br>
6
7
<#escape xx as user?if_exists.userInfo?if_exists[xx]>
8
9
<#noescape>
10
性别:<#if user?if_exists.userInfo?if_exists.gendar?if_exists.i18n?exists>
11
${action.getText(user.userInfo.gendar.i18n)}
12
</#if>
13
</#noescape>
14
15
身份证:${'idCardNo'}<br>
16
17
联系电话:${'telephone'}<br>
18
19
手机:${'mobile'}<br>
20
21
邮箱:${'email'}<br>
22
23
地址:${'address'}<br>
24
25
个人简介:${'resume'}<br>
26
27
</#escape>
28
29
</#escape>
Java Code:
<#escape x as x?if_exists?html>2
3
用户名:${user?if_exists.userName}<br>4

5
姓名:${'name'}<br>6
7
<#escape xx as user?if_exists.userInfo?if_exists[xx]> 8
9
<#noescape>10
性别:<#if user?if_exists.userInfo?if_exists.gendar?if_exists.i18n?exists>11
${action.getText(user.userInfo.gendar.i18n)}12
</#if>13
</#noescape>14
15
身份证:${'idCardNo'}<br>16
17
联系电话:${'telephone'}<br>18
19
手机:${'mobile'}<br>20
21
邮箱:${'email'}<br>22
23
地址:${'address'}<br>24
25
个人简介:${'resume'}<br>26

27
</#escape>28

29
</#escape> 1
class User
2
{
3
private String name;
4
private String userName;
5
private UserInfo userInfo;
6
7
//getter and setter method
8
//
9
}
10
11
class UserInfo
12
{
13
private String idCardNo;
14
private String telephone;
15
private String mobile;
16
private String email;
17
private String address;
18
private String resume;
19
private Sex gendar;
20
//getter and setter method
21
//
22
}
23
24
public enum Sex implements EnumI18n{
25
MALE(0, "el.enum.human.status.male"),
26
FEMALE(1, "el.enum.human.status.female"),
27
28
private String i18n;
29
30
Sex( String i18n) {
31
this.i18n = i18n;
32
}
33
34
public String getI18n() {
35
return this.i18n;
36
}
37
}
class User 2
{3
private String name;4
private String userName;5
private UserInfo userInfo;6

7
//getter and setter method 8
//
9
}10

11
class UserInfo 12
{13
private String idCardNo;14
private String telephone;15
private String mobile;16
private String email;17
private String address;18
private String resume;19
private Sex gendar;20
//getter and setter method 21
//
22
}23

24
public enum Sex implements EnumI18n{ 25
MALE(0, "el.enum.human.status.male"),26
FEMALE(1, "el.enum.human.status.female"),27

28
private String i18n;29
30
Sex( String i18n) {31
this.i18n = i18n;32
}33
34
public String getI18n() {35
return this.i18n;36
}37
}sun

Sex( String i18n)
浙公网安备 33010602011771号