在FreeMarker框架中使用Shiro的Tag标签

可以先了解下shiro

第一步:下载shiro-freemarker-tags GitHub地址:https://github.com/jagregory/shiro-freemarker-tags 

可以先看一下他的说明文档,有一个初步的了解。


第二步:Spring MVC配置

自定义一个ShiroTagFreeMarkerConfigurer继承Spring本身提供的FreeMarkerConfigurer,目的是在FreeMarker的Configuration中添加shiro的配置

public class ShiroTagFreeMarkerConfigurer extends FreeMarkerConfigurer {
  
    @Override
    public void afterPropertiesSet() throws IOException, TemplateException {
        super.afterPropertiesSet();
        this.getConfiguration().setSharedVariable("shiro", new ShiroTags());
    }
      
}

第三步:xml文件配置

<bean id="freemarkerConfig" class="com.xxx.core.shiro.freemarker.ShiroFreeMarkerConfigurer">
	<property name="templateLoaderPath" value="/WEB-INF"/>
	<property name="freemarkerVariables">
		<map>
		</map>
	</property>
	<property name="freemarkerSettings">
		<props>
			<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="whitespace_stripping">true</prop>
			<prop key="auto_import">/ftl/spring.ftl as s</prop>
		</props>
	</property>
</bean>


第四步:使用Shiro Tag

<@shiro.guest>Hello guest!</@shiro.guest>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值