FreeMarker的一些运用心得和技巧
FreeMarker的一些使用心得和技巧
1. TagLib的运用(Spring Security)
在web.xml中添加: <servlet> <servlet-name>JSPSupportServlet</servlet-name> <servlet-class>org.apache.struts2.views.JspSupportServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> 在页面的最上面添加<#assign security=JspTaglibs["http://www.springframework.org/security/tags"] /> 使用的时候: <@security.authorize ifAnyGranted="ROLE_USER,ROLE_ADMIN"> Hello </@security.authorize> 注意中间用的是句号,而不再是冒号,我一开始在这里没注意,花了不少时间解决这个问题 2. Context Path的取得 在Google中搜了一下,有人提问题,但是没有得到解决,后来查资料才知道应该是这样写的: ${request.contextPath} 3. 字符串的比较 字符串不能直接比较大小,我原来两个日期字符串的比较就需要先转换成日期型 <#if dateString1?date("yyyy-MM-dd HH:mm:ss") < dateString2?date("yyyy-MM-dd HH:mm:ss")> 日期小 </#if> 4. <#if><#else> 在if比较时小于号可以直接使用,但是大于号不行,要写成 <#if a > b> </#if> |