0
点赞
收藏
分享

微信扫一扫

Freemarker页面语法


[size=large][color=red]Freemarker页面语法[/color][/size][url]http://jiangsha.iteye.com/blog/372307[/url]

[size=large][color=red]Freemarker 的常见控制结构写法[/color][/size] [url]http://classicning.iteye.com/blog/99664[/url]

[size=medium][color=blue]freemarker为空判断[/color][/size]

<!--判断aaa是否不为空,eclipse插件老报错。--->  
<#if aaa??>  
  ${aaa}  
</#if>  

<#if aaa?if_exists>  
  aaa不存在!  
</#if>  

<#if aaa?exists>  
  aaa存在,值为${aaa}  
</#if>



??是判断对象是否为空,例如:<#if object??>object对象不为空(即object存在)</#if>


如:value="<#if outCar.startNumberKm??>${outCar.startNumberKm}<#elseif startNumberKmByLast??>${startNumberKmByLast} <#else>0</#if>"


?后面要加关键字,例如:<#if object?exists>object对象不为空</#if>


<#if str??>${str?string}</#if><#--将str以字符串形式显示-->


${nowDate?time}<#--将现有时间以时间的格式显示,显示结果如:15:13:05-->


${nowDate?date}<#--以日期格式显示,如:2011-4-28-->(date的格式可以在freemarker.properties文件中配置)


----


freemarker中显示某对象使用${name}.


但如果name为null,freemarker就会报错。如果需要判断对象是否为空:


<#if name??>


……


</#if>


[color=red]当然也可以通过设置默认值${name!""}来避免对象为空的错误[/color]。如果name为空,就以默认值(“!”后的字符)显示。



对象user,name为user的属性,这时user,name都有可能为空,可以写成${(user.name)!""},表示user或者name为null,都显示为空("")。


判断为空 eg:<#if (user.name)??>


举报

相关推荐

0 条评论