美文网首页
FreeMarker整合Shiro 前端标签不生效

FreeMarker整合Shiro 前端标签不生效

作者: 通通小小通 | 来源:发表于2019-06-24 15:21 被阅读0次

今天在用SpringBoot,FreeMarkerShiro整合前端标签,遇到了一点小问题

  • 以前都是用SSM写的Shiro,现在用了SpringBoot,下面就看如何整合前端Shiro标签
  • 首先引入依赖
<dependency>
       <groupId>net.mingsoft</groupId>
       <artifactId>shiro-freemarker-tags</artifactId>
       <version>0.1</version>
</dependency>
  • 其次配置Bean,交给Spring去管理
@Configuration
public class ShiroConfig {

    @Bean
    public FreeMarkerConfigurer freeMarkerConfigurer() throws IOException, TemplateException {
        FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer();
        freeMarkerConfigurer.setTemplateLoaderPath("classpath:templates/");
        freemarker.template.Configuration configuration = freeMarkerConfigurer.createConfiguration();
        configuration.setDefaultEncoding("UTF-8");
        //这里可以添加其他共享变量 比如sso登录地址
        configuration.setSharedVariable("shiro", new ShiroTags());
        freeMarkerConfigurer.setConfiguration(configuration);
        return freeMarkerConfigurer;
    }

}

好了,下面就一起入坑吧
以前用SSM写Shiro的都知道直接用<shiro:hasRole name="administrator">
如果是这样的话,恭喜你成功入坑.用了之后还不报错,只能默默发呆

  • 正确写法
    <@shiro.hasRole name="权限名称">
<@shiro.hasRole name="admin">
  <dd data-name="console">
    <a lay-href="roleManage">角色管理</a>
  </dd>
</@shiro.hasRole>

到此结束,希望大家写代码的时候多一份细心.

相关文章

网友评论

      本文标题:FreeMarker整合Shiro 前端标签不生效

      本文链接:https://www.haomeiwen.com/subject/mgcoqctx.html