<!-- freemarker + shiro(标签) begin -->
<dependency>
<groupId>net.mingsoft</groupId>
<artifactId>shiro-freemarker-tags</artifactId>
<version>1.0.0</version>
</dependency>
<!-- freemarker + shiro(标签) begin -->
import com.jagregory.shiro.freemarker.ShiroTags;
import freemarker.template.TemplateModelException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
import javax.annotation.PostConstruct;
/**
* @Author: SimonHu
* @Date: 2020/6/8 17:02
* @Description:
*/
@Component
public class ShiroTagsFreeMarkerCfg {
private static final Logger log = LoggerFactory.getLogger(ShiroTagsFreeMarkerCfg.class);
@Autowired
private FreeMarkerConfigurer freeMarkerConfigurer;
@PostConstruct
public void setSharedVariable() throws TemplateModelException {
log.info("设置freeMarker 的shiro 标签");
freeMarkerConfigurer.getConfiguration().setSharedVariable("shiro", new ShiroTags());
}
}
<!-- html 静态页面 --><div class="layui-side layui-side-bg layui-larry-side" id="larry-side">
<div class="layui-side-scroll" id="larry-nav-side" lay-filter="side">
<div class="user-photo">
<a class="img" title="我的头像"><img src="http://api.zihexin.net/appimages/ad/20190702/17348339484_1080.png"></a>
<p>你好!<span class="userName"><@shiro.principal property='username'/></span>, 欢迎登录</p>
</div>
<!-- 左侧菜单 -->
<ul class="layui-nav layui-nav-tree">
<menu-item :item="item" v-for="item in menuList"></menu-item>
</ul>
</div>
</div>
springboot使用freemarker shiro标签
点赞
收藏