shiro的freemaker標籤配置使用

由於前端頁面使用freemarker,shiro有jsp標籤,在使用freemarker標籤只借助第三方的梯子shiro-freemarker-tags

1.maven引用包:

 <dependency>
        <groupId>net.mingsoft</groupId>
        <artifactId>shiro-freemarker-tags</artifactId>
        <version>0.1</version>
 </dependency>

2.繼承FreeMarkerConfigurer,進行響應的擴展
public class FreeMarkerConfigExtend extends FreeMarkerConfigurer {
    @Override
    public void afterPropertiesSet() throws IOException, TemplateException {
        super.afterPropertiesSet();
        this.getConfiguration().setSharedVariable("shiro", new ShiroTags());
    }
}

3.在applicationContext.xml文件中配置(以下配置直接拷貝與現有項目)

 <bean id="freemarkerConfig"
          class="com.belle.infrastructure.freemarker.shirotags.FreeMarkerConfigExtend">
        <property name="templateLoaderPaths">
            <list>
                <value>/WEB-INF/ftl/</value>
                <value>/WEB-INF/templates/</value>
            </list>
        </property>
        <property name="defaultEncoding" value="UTF-8" />
        <property name="freemarkerSettings">
            <props>
                <prop key="template_update_delay">0</prop>
                <prop key="locale">zh_CN</prop>
                <prop key="default_encoding">UTF-8</prop>
            </props>
        </property>
    <!--    <property name="freemarkerVariables">
            <map>
                <entry key="BasePath" value="/fms" />
                <entry key="model" value="200" />
                <entry key="xml_escape" value-ref="fmXmlEscape" />
            </map>
        </property> -->

    </bean>


4.freemarker頁面上使用

4.1按鈕控制

<@shiro.hasPermission name="invoice:delete">
        <div class="btn" id='exportReport'>
            <span class="btn_l"></span>
            <b class="ico_btn add"></b>
            <span class="btn_txt">刪除報表</span>
            <span class="btn_r"></span>
        </div>
</@shiro.hasPermission>


4.2 金額等敏感字段控制
 <@shiro.hasPermission name="invoiceAmt:show">
		<@ex.column property="invoiceAmt" title="價稅合計"  style="color:red;font-weight:bold;white-space:nowrap;">
		      ${vo.invoiceAmt?default('0.00')?string('###,##0.00')}
		</@ex.column>
</@shiro.hasPermission>


參考資料:

http://www.sojson.com/blog/143.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章