目前Freemarker對Shrio的標籤還不支持,不過已經有人貢獻出來第三方面解決方案,以下:java
GitHub地址:https://github.com/jagregory/shiro-freemarker-tags
能夠先看一下他的說明文檔,有一個初步的瞭解。git
自定義一個ShiroTagFreeMarkerConfigurer繼承Spring自己提供的FreeMarkerConfigurer,目的是在FreeMarker的Configuration中添加shiro的配置github
public class ShiroTagFreeMarkerConfigurer extends FreeMarkerConfigurer { @Override public void afterPropertiesSet() throws IOException, TemplateException { super.afterPropertiesSet(); this.getConfiguration().setSharedVariable("shiro", new ShiroTags()); } }
下面的Spring mvc配置web
<bean id="freemakerCongfig" class="com.xxx.web.freemarker.ShiroTagFreeMarkerConfigurer"> <property name="templateLoaderPath" value="/WEB-INF/views/" /> <property name="freemarkerSettings"> <props> <prop key="defaultEncoding">UTF-8</prop> <prop key="classic_compatible">true</prop> </props> </property> </bean>
<@shiro.guest>Hello guest!</@shiro.guest>