@(Xcaspar)[shiro|freemarker]
JSP页面中调用shiro标签十分方面,只需要导入:
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
但是和freemarker联合使用,需要做一下调整:
编写一个类,继承org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer
此类,重写此类的afterPropertiesSet()
方法,用com.jagregory.shiro.freemarker.ShiroTags
替换原有shiro标签,实例如下:
public class ShiroTagFreeMarkerConfigurer extends FreeMarkerConfigurer {
@Override
public void afterPropertiesSet() throws IOException, TemplateException {
super.afterPropertiesSet();
this.getConfiguration().setSharedVariable("shiro", new ShiroTags());
}
}
在页面中使用<@shiro.xxx></@shiro.xxx > 来替换JSP中shiro:xxx</shiro:xxx>标签