ShiroTagFreeMarkerConfigurer.java
/**
* freemarker集成Shiro标签
*/
@Component
public class ShiroTagFreeMarkerConfigurer implements InitializingBean {
@Autowired
private Configuration configuration;
@Autowired
private FreeMarkerViewResolver resolver;
@Override
public void afterPropertiesSet() throws Exception {
// 加上这句后,可以在页面上使用shiro标签
configuration.setSharedVariable("shiro", new ShiroTags());
// 加上这句后,可以在页面上用${context.contextPath}获取contextPath
resolver.setRequestContextAttribute("context");
}
}
pom文件
<dependency>
<groupId>net.mingsoft</groupId>
<artifactId>shiro-freemarker-tags</artifactId>
<version>0.1</version>
</dependency>
页面,角色和权限都是从Realm中的doGetAuthorizationInfo方法设置数据
<@shiro.principal property="userName"/>
<@shiro.hasRole name="admin">
</@shiro.hasRole>