可以先了解下shiro
第一步:下载shiro-freemarker-tags GitHub地址:https://github.com/jagregory/shiro-freemarker-tags
可以先看一下他的说明文档,有一个初步的了解。
第二步:Spring MVC配置
自定义一个ShiroTagFreeMarkerConfigurer继承Spring本身提供的FreeMarkerConfigurer,目的是在FreeMarker的Configuration中添加shiro的配置
- public class ShiroTagFreeMarkerConfigurer extends FreeMarkerConfigurer {
-
- @Override
- public void afterPropertiesSet() throws IOException, TemplateException {
- super.afterPropertiesSet();
- this.getConfiguration().setSharedVariable("shiro", new ShiroTags());
- }
-
- }
第三步:xml文件配置
- <bean id="freemarkerConfig" class="com.xxx.core.shiro.freemarker.ShiroFreeMarkerConfigurer">
- <property name="templateLoaderPath" value="/WEB-INF"/>
- <property name="freemarkerVariables">
- <map>
- </map>
- </property>
- <property name="freemarkerSettings">
- <props>
- <prop key="template_update_delay">0</prop>
- <prop key="defaultEncoding">UTF-8</prop>
- <prop key="url_escaping_charset">UTF-8</prop>
- <prop key="locale">zh_CN</prop>
- <prop key="boolean_format">true,false</prop>
- <prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop>
- <prop key="date_format">yyyy-MM-dd</prop>
- <prop key="time_format">HH:mm:ss</prop>
- <prop key="number_format">0.######</prop>
- <prop key="whitespace_stripping">true</prop>
- <prop key="auto_import">/ftl/spring.ftl as s</prop>
- </props>
- </property>
- </bean>
第四步:使用Shiro Tag
<@shiro.guest>Hello guest!</@shiro.guest>