写文章

在spring boot项目中,如何整合freemarker与shiro标签使用

2018-11-29 10:43:46

4956 | 0 | 0

一、导入依赖包

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

二、在项目中添加配置

package com.web.common.config;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.jagregory.shiro.freemarker.ShiroTags;

import freemarker.template.Configuration;

@Component
public class PlatformFreeMarkerConfigurer implements InitializingBean {

	@Autowired
	private Configuration configuration;

	@Override
	public void afterPropertiesSet() throws Exception {
		// 加上这句后,可以在页面上使用shiro标签
		configuration.setSharedVariable("shiro", new ShiroTags());
	}
}

三、

<@shiro.hasPermission name="admin:add">
    <a href="${base}/admin/user/role/add">添加角色</a>
</@shiro.hasPermission>

<@shiro.hasPermission name="admin:update">
    <a href="${base}/admin/user/role/edit?id=${bean.id}">修改</a>
    <a href="${base}/admin/user/role/delete?id=${bean.id}">删除</a>
</@shiro.hasPermission>


0

收藏
分享