Shiro Freemarker标签的使用

Shiro 提供了JSP 的一套JSTL 标签,用于做JSP 页面做权限控制的。可以控制一些按钮和一些超链接,或者一些显示内容。

引用包:

<!-- freemarker + shiro(标签) begin -->
<dependency>
    <groupId>net.mingsoft</groupId>
    <artifactId>shiro-freemarker-tags</artifactId>
    <version>0.1</version>
</dependency>
<!-- freemarker + shiro(标签) begin -->

他不是 shiro 官方提供的。

Java代码:

public class FreeMarkerConfigExtend extends FreeMarkerConfigurer {
    @Override  
    public void afterPropertiesSet() throws IOException, TemplateException {  
        super.afterPropertiesSet();
        Configuration cfg = this.getConfiguration();
        cfg.setSharedVariable("shiro", new ShiroTags());//shiro标签
        cfg.setNumberFormat("#");//防止页面输出数字,变成2,000
        //可以添加很多自己的要传输到页面的[方法、对象、值]
    }  
}

配置文件:

<!-- 配置freeMarker 拓展-->
<bean id="freemarkerConfig"
    class="com.sojson.core.freemarker.extend.FreeMarkerConfigExtend">
    <property name="templateLoaderPath">
        <value>/WEB-INF/ftl/</value>
    </property>
    <property name="freemarkerVariables">
        <map>
            <entry key="xml_escape" value-ref="fmXmlEscape" />
            <entry key="api" value-ref="api"/>
        </map>
    </property>
    <property name="defaultEncoding">
        <value>utf-8</value>
    </property>
    <property name="freemarkerSettings">
        <props><!-- 315360000 -->
                <prop key="template_update_delay">0</prop>
                <prop key="defaultEncoding">UTF-8</prop>
                <prop key="url_escaping_charset">UTF-8</prop>
                <prop key="locale">zh_CN</prop>
                <prop key="boolean_format">true,false</prop>
                <prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop>
                <prop key="date_format">yyyy-MM-dd</prop>
                <prop key="time_format">HH:mm:ss</prop>
<!--            <prop key="number_format">0.######</prop>-->
            <prop key="number_format">#</prop>
            <prop key="whitespace_stripping">true</prop>
            <prop key="auto_import">
                /common/config/top.ftl as _top,
                /common/config/left.ftl as _left,
                /common/config/html.ftl as _html,
                /common/config/bottom.ftl as _footer,
                /common/config/menu.ftl as _menu
            </prop>
        </props>
    </property>
</bean>

页面使用

欢迎[<@shiro.principal property="username"/>]登录

更多使用方法点击原文

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值