FreeMarker 对null值的处理技巧
来源:互联网 发布:java aop 日志记录 编辑:程序博客网 时间:2024/05/21 14:47
以下引用官方描述:
引用
The FreeMarker template language doesn't know the Java language null at all. It doesn't have null keyword, and it can't test if something is null or not.
1.判断是否存在,通过exists关键字或者"??"运算符。都将返回一个布尔值
user.name?exists
user.name??
<#if user.name?exists> //TO DO</#if><#if user.age??> //TO DO</#if>
2.忽略null值
假设前提:user.name为null
${user.name},异常
${user.name!},显示空白
${user.name!'vakin'},若user.name不为空则显示本身的值,否则显示vakin
${user.name?default('vakin')},同上
${user.name???string(user.name,'vakin')},同上
!:default value operator,语法结构为:unsafe_expr!default_expr,
比如 ${mouse!"No mouse."} 当mouse不存在时,返回default value;
(product.color)!"red" 这种方式,能够处理product或者color为miss value的情况;
而product.color!"red"将只处理color为miss value的情况
(product.color)!"red" 这种方式,能够处理product或者color为miss value的情况;
而product.color!"red"将只处理color为miss value的情况
?? : Missing value test operator ,测试是否为missing value
unsafe_expr?? :product.color??将只测试color是否为null
(unsafe_expr)??:(product.color)??将测试product和color是否存在null
- FreeMarker 对null值的处理技巧
- FreeMarker 对null值的处理
- FreeMarker对null值的处理
- freemarker 对null 的处理
- freemarker 处理null值
- freemarker中空值 null的处理 ?exists ?if_exists ?default(“”)
- freemarker中空值 null的处理 ?exists ?default("")
- freemarker中空值 null的处理 ?exists ?if_exists ?default(“”)
- FreeMarker中的null处理
- oracle 对null值的处理
- count()函数对null值的处理
- oracle中对null值的处理
- GROUP FUNCTION对NULL值的处理
- java中对null值的处理
- 不同数据库对null值的处理
- FreeMarker的怎么对空值的处理
- mysql 对null的处理
- JSON对null的处理
- STM32 RDS解码
- NO.80 从与L君饭间聊天再扯开去……
- Flex 4.5下 mx:TabNavigator 与s:TextInput一起使用的Bug
- sqlserver 递归查询
- inkscape 详解
- FreeMarker 对null值的处理技巧
- this和getApplicationContext区别
- 高级程序员装逼指南
- 将smartform转换成pdf并上传
- Hibernate实现模糊查询的方法
- C++ 对象的内存布局(下)【转】
- C++编程思想学习——模版介绍
- 生成自己的 tclsh
- Gallery和GridView浅析