springboot使用 freemarker shiro标签

1.添加 shiro-freemarker-tags 库:

compile("net.mingsoft:shiro-freemarker-tags:0.1")

2.创建 ShiroTagsFreeMarkerCfg

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer

import com.jagregory.shiro.freemarker.ShiroTags

import freemarker.template.Configuration
import freemarker.template.TemplateException
import freemarker.template.TemplateModelException
@Component
class ShiroTagsFreeMarkerCfg  {
	@Autowired
	private FreeMarkerConfigurer freeMarkerConfigurer;
	
	@PostConstruct
	public void setSharedVariable() throws TemplateModelException {  
		println "设置freeMarker 的shiro 标签"
		freeMarkerConfigurer.getConfiguration().setSharedVariable("shiro", new ShiroTags());  
	}  
}

3.在模板文件中使用

<html>
<head>
<title>Welcome!</title>
</head>
<body>
<#-- 注释部分 -->
<#-- 下面使用插值 -->
<p>We have these users: </p>
<ul>
首页
    <@shiro.hasPermission name="权限添加">  
    	User Account:${user.userAccount} <br/>
    	用户        [<@shiro.principal />]拥有权限添加权限
    </@shiro.hasPermission>   
<ul>
</body>
</html> 

 

转载于:https://my.oschina.net/jaakan/blog/1647056

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值