posts - 0, comments - 0, trackbacks - 0, articles - 7

Freemarker

Posted on 2011-07-20 17:21 小康 阅读(215) 评论(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>


B
oolean类型的值不能直接输出(无法直接转换成string类型)

格式化输出:boolean_expr?string(yes,no)  


只有注册用户登录后才能发表评论。


网站导航: