springboot 自定义权限标签(tld),在freemarker引用
来源:互联网 发布:广州数据库定制 编辑:程序博客网 时间:2024/06/11 17:04
第一步:引入jar包
<dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp-api</artifactId> <version>2.2.1-b03</version> </dependency>
第二步:自定义标签类
import java.util.Map;import java.util.Set;import javax.servlet.http.HttpServletRequest;import org.jasig.cas.client.authentication.AttributePrincipal;import org.springframework.web.servlet.tags.RequestContextAwareTag;import com.goodidea.sso.dto.PrivilegesDto;import com.goodidea.sso.dto.ResourcesDto;import com.goodidea.sso.service.PrivilegesService;/** * * @ClassName: PrivilegeTag * @Description: 权限标签类 * @author lsg* @date 2017年9月12日 下午5:36:01 * */public class PrivilegeTag extends RequestContextAwareTag{ private static final long serialVersionUID = 534416848523276042L; private String menuAlias; private String priAlias; public String getMenuAlias() { return menuAlias; } public void setMenuAlias(String menuAlias) { this.menuAlias = menuAlias; } public String getPriAlias() { return priAlias; } public void setPriAlias(String priAlias) { this.priAlias = priAlias; } @Override protected int doStartTagInternal() { // TODO Auto-generated method stub boolean result = false; try { HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); AttributePrincipal principal = (AttributePrincipal)request.getUserPrincipal(); Map<String, Object> attributes = principal.getAttributes(); String username=(String) attributes.get("username"); PrivilegesService privilegesService= (PrivilegesService)this.getRequestContext().getWebApplicationContext().getBean("privilegesServiceImpl"); Set<ResourcesDto> dto = privilegesService.findResourcesByUsername(username); for (ResourcesDto resourcesDto : dto) { if(this.menuAlias.equals(resourcesDto.getAlias())){ for (PrivilegesDto pdto : resourcesDto.getPrivileges()) { if(this.priAlias.equals(pdto.getAlias())){ result = true; } } } } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); result =false; } return result? EVAL_BODY_INCLUDE : SKIP_BODY; }}
第三步:创建tld标签,放入在web-inf下
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN" "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd"><taglib> <tlibversion>1.0</tlibversion> <jspversion>1.1</jspversion> <shortname>privilege</shortname> <tag> <name>privilege</name> <tagclass>com.goodidea.sso.core.PrivilegeTag</tagclass> <bodycontent>empty</bodycontent> <!--这里如果设为empty,则无body--> <attribute> <name>menuAlias</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>priAlias</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> </tag></taglib>
第四:页面引用
<#assign p=JspTaglibs["/WEB-INF/tld/privilege.tld"] />
注意tld,如果不在web.xml上进行引入的话,就放在web-inf下,要不然会报找不到tld资源异常
阅读全文
0 0
- springboot 自定义权限标签(tld),在freemarker引用
- SpringBoot 实现Freemarker自定义标签
- freemarker 自定义标签控制权限
- 自定义权限模块2——自定义tld标签
- 如何引用自定义标签库中的tld文件
- 如何引用自定义标签库中的tld文件
- TLD自定义标签
- TLD自定义标签
- 自定义tld 标签
- 自定义标签 tld
- jsp自定义标签tld
- 自定义标签 tld
- TLD自定义标签步骤
- freemarker 自定义freeMarker标签
- jsp:自定义标签实例(TLD)
- 自定义标签文件--tld注意事项
- 自定义标签tld的使用
- 自定义标签tld的使用
- iOS11开发新增功能大全
- UGUI研究院之SpritePacker打包教程
- 单例模式
- PyQuery 用法和实例
- windows安装python以及相关库
- springboot 自定义权限标签(tld),在freemarker引用
- HBase 简介、架构、工作原理深析——(一)
- mysql行列转换
- ios——备忘__attribute__总结(一)
- mybatis学习一
- js阻止事件
- Requests 用法和实例
- a.active和a:active的区别
- MV3D -- Training