关于 springboot thymeleaf 整合shiro 标签失效不进入doGetAuthorizationInfo问题

@TOC关于 springboot thymeleaf 整合shiro 标签失效不进入doGetAuthorizationInfo问题

之前是使用注解 @RequiresPermissions()在每个方法加上,就可以进入doGetAuthorizationInfo授权方法,后面改成前端只使用shiro标签触发调用doGetAuthorizationInfo方法,不知道为什么死活不行,百度了四天,用了各种方法都不行,今天终于解决了,

1.先导入依赖

    <dependency>
        <groupId>com.github.theborakompanioni</groupId>
        <artifactId>thymeleaf-extras-shiro</artifactId>
        <version>2.0.0</version>
    </dependency>

2.引用bean
@Bean
public ShiroDialect shiroDialect() {
return new ShiroDialect();
}

3.重点,我就是死在这里,前面2个百度上一搜大把人都说加这两个就可以了,我反正加了就不行,后面加了下面这个就可以了。
因为springboot支持使用 thymeleaf模板引擎,所以这个也要引入
在这里插入图片描述
**

下面是我的 thymeleaf配置类,仅供参考,不可全抄,看重点,把上面图划线的地方拿走就可以了,不然项目运行不起来不要怪我

**

import at.pollux.thymeleaf.shiro.dialect.ShiroDialect;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.HttpPutFormContentFilter;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.thymeleaf.dialect.IDialect;
import org.thymeleaf.spring4.SpringTemplateEngine;
import org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver;
import org.thymeleaf.spring4.view.ThymeleafViewResolver;

import javax.servlet.MultipartConfigElement;
import java.util.HashSet;
import java.util.Set;

/**

  • thymeleaf配置类
    */
    @Configuration
    public class WebMvcConfig extends WebMvcConfigurerAdapter implements ApplicationContextAware {

    private ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    this.applicationContext = applicationContext;
    }

    /**

    • 模板资源解析器
    • @return
      */
      @Bean
      @ConfigurationProperties(prefix = “spring.thymeleaf”)
      public SpringResourceTemplateResolver templateResolver() {
      SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();
      templateResolver.setApplicationContext(this.applicationContext);
      templateResolver.setCharacterEncoding(“UTF-8”);
      templateResolver.setCacheable(false);
      return templateResolver;
      }

    /**

    • Thymeleaf标准方言解释器
      */
      @Bean
      public SpringTemplateEngine templateEngine() {
      SpringTemplateEngine templateEngine = new SpringTemplateEngine();
      templateEngine.setTemplateResolver(templateResolver());
      // 支持Spring EL表达式
      templateEngine.setEnableSpringELCompiler(true);

      Set additionalDialects = new HashSet();

      additionalDialects.add(new ShiroDialect());

      templateEngine.setAdditionalDialects(additionalDialects);

      return templateEngine;
      }

    /**

    • 视图解析器
      */
      @Bean
      public ThymeleafViewResolver viewResolver() {
      ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
      viewResolver.setTemplateEngine(templateEngine());
      return viewResolver;
      }

    @Bean
    public HttpPutFormContentFilter httpPutFormContentFilter() {
    return new HttpPutFormContentFilter();
    }

}
到此大功告成

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值