Shiro 提供了JSP 的一套JSTL 标签,用于做JSP 页面做权限控制的。可以控制一些按钮和一些超链接,或者一些显示内容。
<!-- freemarker + shiro(标签) begin -->
<dependency>
<groupId>net.mingsoft</groupId>
<artifactId>shiro-freemarker-tags</artifactId>
<version>0.1</version>
</dependency>
<!-- freemarker + shiro(标签) begin -->
他不是 shiro 官方提供的。
public class FreeMarkerConfigExtend extends FreeMarkerConfigurer {
@Override
public void afterPropertiesSet() throws IOException, TemplateException {
super.afterPropertiesSet();
Configuration cfg = this.getConfiguration();
cfg.setSharedVariable("shiro", new ShiroTags());//shiro标签
cfg.setNumberFormat("#");//防止页面输出数字,变成2,000
//可以添加很多自己的要传输到页面的[方法、对象、值]
}
}
<!-- 配置freeMarker 拓展-->
<bean id="freemarkerConfig"
class="com.sojson.core.freemarker.extend.FreeMarkerConfigExtend">
<property name="templateLoaderPath">
<value>/WEB-INF/ftl/</value>
</property>
<property name="freemarkerVariables">
<map>
<entry key="xml_escape" value-ref="fmXmlEscape" />
<entry key="api" value-ref="api"/>
</map>
</property>
<property name="defaultEncoding">
<value>utf-8</value>
</property>
<property name="freemarkerSettings">
<props><!-- 315360000 -->
<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="number_format">#</prop>
<prop key="whitespace_stripping">true</prop>
<prop key="auto_import">
/common/config/top.ftl as _top,
/common/config/left.ftl as _left,
/common/config/html.ftl as _html,
/common/config/bottom.ftl as _footer,
/common/config/menu.ftl as _menu
</prop>
</props>
</property>
</bean>
欢迎[<@shiro.principal property="username"/>]登录