web应用中使用freemarker控制权限问题
重点:freemarker调用static方法即可.
在tag.html中定义宏:
<#macro checkUser flag="">
<#if static["com.system.cache.SystemCache"].checkUser(flag)>
<#nested>
</#if>
</#macro>
在页面中调用:
引入tag.html
<#import "common/tag.html" as tag>
<@tag.checkUser flag=true> Html Content!! </@tag.checkUser>
SystemCache类中的checkUser方法如下:
public static boolean checkUser(boolean flag){
return flag;
}
注意:
自定义指令可以有嵌套内容,使用<#nested>指令,执行自定义指令开始和结束标记之间的模板片段。例如:
<#macro greet>
<#nested>
</#macro>
<@greet>hello Jack!</@greet>
输出为
hello Jack!
重点:freemarker调用static方法即可.
在tag.html中定义宏:
<#macro checkUser flag="">
<#if static["com.system.cache.SystemCache"].checkUser(flag)>
<#nested>
</#if>
</#macro>
在页面中调用:
引入tag.html
<#import "common/tag.html" as tag>
<@tag.checkUser flag=true> Html Content!! </@tag.checkUser>
SystemCache类中的checkUser方法如下:
public static boolean checkUser(boolean flag){
return flag;
}
注意:
自定义指令可以有嵌套内容,使用<#nested>指令,执行自定义指令开始和结束标记之间的模板片段。例如:
<#macro greet>
<#nested>
</#macro>
<@greet>hello Jack!</@greet>
输出为
hello Jack!