Posted on 2011-07-20 17:21
小康 阅读(213)
评论(0) 编辑 收藏 所属分类:
freearker
1、判断对象是否存在(null)
expr?exsits 返回true/false
expr?? 返回true/false
(user.name)?? 将测试user对象和user属性name是否存在null
设置默认值:expr!default_expr 若对象不存在返回default_expr
2、空值处理方法
1)对变量设置默认值:expr!default_expr
2)属性classic_compatible=true (若变量为null则替换为空字符串)
a.在ftl文件前加入<#setting classic_compatible=true>
b.class目录下添加freemarker.properties文件:加入classic_compatible=true (struts或spring环境)
c.spring配置:
<bean id="freemarkerConfig"
class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<property name="freemarkerSettings">
<props>
<prop key="classic_compatible">true</prop>
</props>
</property>
</bean>
Boolean类型的值不能直接输出(无法直接转换成string类型)
格式化输出:boolean_expr?string(“yes”,”no”)