Skip to content

Instantly share code, notes, and snippets.

@xcaspar
Created July 21, 2015 07:41
Show Gist options
  • Save xcaspar/ff5557d95719a3496228 to your computer and use it in GitHub Desktop.
Save xcaspar/ff5557d95719a3496228 to your computer and use it in GitHub Desktop.

shiro与freemarker标签集成

@(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>标签

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment