二、使用freemarker踩的一些坑
1、关于null值:freemarker对于null值得校验很严格,如果出现null值,而在页面中不进行判断,则会发生异常,通常情况下判断方式有两种:
(1)在页面中使用${prop??}进行判断,或使用${prop?""},若为空则显示“”
(2)可使用配置classic_compatible=true,此种方式只能判断一层,如user.prop为null,显示为空,若user为空,则仍会发生异常。目前的这种情况可使用第一种方式,或者手动创建一个空的对象,保证外层对象不为null即可。
2、freemaker遍历List:
<#list userlist as user></#list>
3、freemarker遍历Map:
<#list userMap?keys as userKey>
key:${userKey}
value:${userMap[userKey]}
</#if>
4、在freemarker页面中使用request对象:配置requestContextAttribute=request,即可使用request,如:
<#assign webroot=request.getContextPath()>
<#assign root=request.contextPath />
6、freemarker定义变量:<#assign name="xxx">,使用:${name}即可
7、freemarker引入其他页面:<#include "xx.ftl">
8、table的td内容自动换行:<td style="word-break:break-all">
9、p标签内容换行:<p style="word-wrap:break-word"></p>
10、实现格式化显示:定义时间显示格式:<#setting datetime_format="yyyy-MM-dd HH:mm:ss"/>
使用:${serviceInfo.createTime?number_to_datetime}
11、在使用jquery的datatable时,如果页面中存在注释,一定要特别注意,不能直接使用<!-- -->这样的注释,要用<#--<!-- 修改中,审核驳回 可修改 –>-->,否则注释内容无效,会被datable的搜索功能识别到。暂时还不清楚是谁的原因导致的。
11、在使用jquery的datatable时,如果页面中存在注释,一定要特别注意,不能直接使用<!-- -->这样的注释,要用<#--<!-- 修改中,审核驳回 可修改 –>-->,否则注释内容无效,会被datable的搜索功能识别到。暂时还不清楚是谁的原因导致的。
====bootstrap
列表中显示操作下拉菜单:
- <div class="btn-group" style="margin-bottom: 1px !important;">
- <a class="btn green" href="#" data-toggle="dropdown">
- <i class="icon-cogs"></i>操作
- <i class="icon-angle-down"></i>
- </a>
- <ul class="dropdown-menu pull-right">
- <li><a href="javascript:;" onclick="editBusinessType(${apiBusinessType.id})"><iclassiclass="icon-edit"></i>编辑</a></li>
- <li><a href="javascript:;" onclick="deleteBusinessType(${apiBusinessType.id})"><iclassiclass="icon-remove"></i>删除</a></li>
- </ul>
- </div>