spring-boot 配置thymeleaf模板引用shiro标签
application.yml
spring:
thymeleaf:
cache: false
suffix: .html
encoding: UTF-8
prefix: classpath:/views/
content-type: text/html
mode: LEGACYHTML5
main.html
<li shiro:hasRole ="admin">
<shiro:principal property="userName"/>
pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>com.github.theborakompanioni</groupId>
<artifactId>thymeleaf-extras-shiro</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-core</artifactId>
<version>1.2.4</version>
</dependency>
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>1.9.22</version>
</dependency>
ShiroConfig.java
@Bean
public SecurityManager securityManager() {
DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
// 设置realm.
securityManager.setRealm(customRealm);
return securityManager;
}