javaweb+SSH实现简单的权限管理系统

来源:互联网 发布:泰瑞克埃文斯 数据 编辑:程序博客网 时间:2024/05/17 20:29

javaweb+SSH实现简单的权限管理系统

权限管理,平时里很多地方我们都可以看到,比如聊QQ时群里的群主、管理员以及成员之间的功能是不一样的……大家一定会遇到的一个问题,所以整理 一下自己写权限系统的一些经验给大家,只起参考作用,也望大家笑纳。哈哈哈

一、为什么要实现权限系统

1、 系统中的权限系统,缺少组织结构管理。例如:树型的组织结构,有些系统虽然考虑了分层,但是没有考虑分多少层,
组织结构是否考虑了集团公司,全国连锁经营这种模式,实际上就是很多个独立单位的概念。很多系统遇到这个问题,
就需要重新做整个系统。
2、 不同登陆用户要有不同的权利,而且要有不同的菜单,如果不能灵活的修改他们的权限,那用户需求一旦变化,不是就
很郁闷了。系统要能够解决这个问题,我们就要灵活的控制每个页面。即便是系统已经开发完成,投入运行,也可以
通过修改配置文件,而实现权限的重新调整。

二、权限简单控制原理:

规则一:每个登陆的用户,可以有多个角色,
规则二:每个角色又可以访问多个功能点,
规则三:每个功能点又由多个页面组成。
根据这个对应关系,就可以让每个用户对应到不同的页面,如果进行细致设置,基本上可以解决了应用中的很多情况。

三、名词解释:

页面(URL):在web开发中也称为URL,最朴素的权限控制,就是基于页面的控制,即赋予访问者可以访问页面的范围,
在系统记录所有的页面,配置权限时,将允许访问的页面,赋予使用者.虽然简单,却很直接和容易理解.基于这个思
想,将软件的URL作为权限,进行控制.将所有的URL进行记录.但如果直接将URL作为权限,配置给使用者,
是相当麻烦的.因为,一个操作功能,往往不是在一个请求内完成的,这就意味着为了让使用者有权利完成一个功能,
就必须将一组URL赋予使用者,以便其访问,显然这样给系统管理和维护带来了很多不方便.因此我们就需要功能点.

功能点: 是一组不可分割URL,因为这组URL共同完成一个功能,因此他们是不可分开的.使用者要正常完成操作,就必须有权
访问这组URL中的每一个.这样,将一个功能点赋予使用者,也就意味着这个使用者有访问这些URL的能力.在业务中,
系统管理员不用关心到底什么权限对应哪些URL,只要将功能点赋予使用者,就可以关联URL了,完成授权过程.

角色: 角色又可以成为”岗位”,它是一组功能点.很多时候,多个使用者的操作权限是相同的,例如一个部门中,大家都有察看自
己邮箱的权利,都有修改自己口令和基本信息的权利,这时,就将邮箱功能点,修改口令,基本信息维护这几个功能点集合起
来,建立一个角色–”操作员岗”,那么,在给使用者授权时,只要将这个角色赋予使用者,该使用者就拥有了相应的功能操
作权限.适合多使用者权限的管理,尤其是使用者数量众多,而且权限相同或者类似时,可以减少很多麻烦,减少出错概率.
同时,一个使用者可以同时拥有多个角色,这些角色所代表的权限,使用者可以同时拥有,是权限的并集.
例如一个部门经理可以有”操作员”角色,具备基本的操作权限,同时还可以将”部门审核员”这个角色授予他,这样可以作操
作部分管理功能.这样做,可以灵活的组合和配置使用者权限,适应复杂权限管理.

用户:是软件系统使用者的系统账号.每个使用者,都有自己独一无二的账号,系统通过这个账号来识别不同的使用者.账号的安全
是通过使用者口令加以保护的.口令在系统中是用加密的方式进行保存,避免了通过数据库系统泄漏使用者口令的问题.系统
使用者是通过”用户”与”功能点”关联,完成使用者的授权,在使用者登陆系统后,也是通过”用户”来认证当前使用者的权限.

四、数据库设计:

一个用户可以拥有多个权限,同时一个权限也可以赋予多个用户,那么用户和权限就是多对多的关系,那么久需要角色
表来维护和链接用户和权限的关系。通过用户和角色关联,角色和权限关联,从而实现用户和权限的一个间接关系。那么
问题又来了,用户和角色也是多对多的关系,角色和权限也是多对多的关系,我们还需要两张中间表,就是
用户角色表和角色权限表。
1、用户表:登录的用户
2、角色表:与权限相关联
3、权限(功能)表:与角色相关联
4、用户角色表:用户和角色的中间表
5、角色功能表:角色和功能的中间表

五、简单程序设计:

1、导入相关的包

以及SPRING的相关包
1、用户,角色,权限(功能),角色权限,用户角色五个实体类对应五张表(省略…)
2、action层调用service层,service层调用dao层
action是界面层:管理业务(service)调度和管理跳转的,是一个管理器,只负责管理
service是业务逻辑层:管理具体功能和逻辑的,负责实施
DAO数据访问层:只完成增删改查,只负责封装,具体的如何去实现由service实施
3、action:实现页面的功能
service:先定义一个接口抽象出具有的功能,再由impl去具体的实现。dao也是如此

六、源码

在写权限管理的时候最头痛的地方也就是权限功能的模块了,但是不管是怎样的一个业务也是数据的增删改查操作

以下是功模块的源码

 

 

1、功能块的实体类对象

package com.myauth.functions.entity;import java.util.*;import javax.persistence.*;import com.myauth.module.entity.Module;import com.myauth.relationship.entity.RoleFunction;//把这个类实体化,并设置其对应表@Entity@Table(name = "functions")public class Function implements java.io.Serializable {    // 对应数据表字段的变量    private Integer id;    private Module module;    private String url;    private String functionname;    // 对应一对多关联变量    private Set<RoleFunction> roleFunctions = new HashSet<RoleFunction>(0);    // 空构造方法    public Function() {    }    // 设置关联属性    @ManyToOne(cascade = {}, fetch = FetchType.LAZY)    @JoinColumn(name = "moduleid")    public Module getModule() {        return module;    }    public void setModule(Module module) {        this.module = module;    }    // 设置表中对应字段    @Column(name = "functionname")    public String getFunctionname() {        return functionname;    }    public void setFunctionname(String functionname) {        this.functionname = functionname;    }    // 设置变量id对应数据库表字段为id,且为主键,并设置其主键策略为SEQUENCE    @Id    @GeneratedValue(strategy = GenerationType.SEQUENCE)    @Column(name = "id")    public Integer getId() {        return this.id;    }    public void setId(Integer id) {        this.id = id;    }    // 设置表中对应字段    @Column(name = "url")    public String getUrl() {        return this.url;    }    public void setUrl(String url) {        this.url = url;    }    // 设置关联属性    @OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "function")    public Set<RoleFunction> getRoleFunctions() {        return this.roleFunctions;    }    public void setRoleFunctions(Set<RoleFunction> roleFunctions) {        this.roleFunctions = roleFunctions;    }}


2、定义一个功能DAO接口并实现,以下是实现代码

package com.myauth.functions.dao;import java.util.List;import javax.persistence.*;import com.myauth.functions.entity.Function;import com.myauth.persistence.EntityManagerHelper;public class FunctionDAO implements IFunctionDAO {    // 声明静态常量    public static final String URL = "url";    public static final String FUNCTIONNAME = "functionname";    // 得到实体管理器    private EntityManager getEntityManager() {        return EntityManagerHelper.getEntityManager();    }    // 新增数据    public void save(Function entity) {        EntityManagerHelper.beginTransaction();        try {            getEntityManager().persist(entity);            EntityManagerHelper.commit();        } catch (RuntimeException re) {            EntityManagerHelper.rollback();            throw re;        }    }    // 删除数据    public void delete(Function entity) {        EntityManagerHelper.beginTransaction();        try {            entity = getEntityManager().getReference(Function.class,                    entity.getId());            getEntityManager().remove(entity);            EntityManagerHelper.commit();        } catch (RuntimeException re) {            EntityManagerHelper.rollback();            throw re;        }    }    // 修改数据    public Function update(Function entity) {        EntityManagerHelper.beginTransaction();        try {            Function result = getEntityManager().merge(entity);            EntityManagerHelper.commit();            return result;        } catch (RuntimeException re) {            EntityManagerHelper.rollback();            throw re;        }    }    // 通过id查询数据    public Function findById(Integer id) {        try {            Function instance = getEntityManager().find(Function.class,                    id);            return instance;        } catch (RuntimeException re) {            throw re;        }    }    // 通过表中一个字段查询数据    @SuppressWarnings("unchecked")    public List<Function> findByProperty(String propertyName,            final Object value) {        try {            final String queryString = "select model from Function model where model."                    + propertyName + "= :propertyValue";            Query query = getEntityManager().createQuery(queryString).setHint(                    "toplink.refresh", true);            query.setParameter("propertyValue", value);            return query.getResultList();        } catch (RuntimeException re) {            throw re;        }    }    // 查询所有数据    @SuppressWarnings("unchecked")    public List<Function> findAll() {        try {            final String queryString = "select model from Function model";            Query query = getEntityManager().createQuery(queryString).setHint(                    "toplink.refresh", true);            return query.getResultList();        } catch (RuntimeException re) {            throw re;        }    }}


3、定义一个service接口实现具体的增删改查操作,并实现,以下是实现代码

package com.myauth.functions.service;import java.util.ArrayList;import java.util.List;import com.myauth.functions.dao.IFunctionDAO;import com.myauth.functions.entity.Function;import com.myauth.module.dao.IModuleDAO;import com.myauth.module.entity.Module;import com.myauth.relationship.dao.IRoleFunctionDAO;import com.myauth.relationship.entity.RoleFunction;public class FunctionFacade implements IFunctionFacade {    private IRoleFunctionDAO rfd;    private IFunctionDAO fd;    private IModuleDAO md;    // getter和setter方法省略    public IRoleFunctionDAO getRfd() {        return rfd;    }    public void setRfd(IRoleFunctionDAO rfd) {        this.rfd = rfd;    }    public IFunctionDAO getFd() {        return fd;    }    public void setFd(IFunctionDAO fd) {        this.fd = fd;    }    public IModuleDAO getMd() {        return md;    }    public void setMd(IModuleDAO md) {        this.md = md;    }    // 浏览可执行功能    public List<Function> findFunction(List<Integer> rid, Module m) {        List<Function> listfunction = new ArrayList<Function>();        for (Integer i : rid) {            listfunction.addAll(rfd.findFInRM(i, m));        }        return listfunction;    }    // 浏览全部功能    public List<Function> findFByMId(Module m) {        return fd.findByProperty("module.id", m.getId());    }    // 单查功能    public Function findSingleFunction(Function f) {        return fd.findById(f.getId());    }    // 修改功能    public void modifyFunction(Function f) {        fd.update(f);    }    // 新增功能    public void newFunction(Function f, Integer mid) {        Module pf = new Module();        pf = md.findById(mid);        // 设置当前功能所属模块id        f.setModule(pf);        fd.save(f);    }    // 删除功能    public void removeFunction(Function f) {        // 删除功能时将其在关联表中的所有数据删除        for (RoleFunction roleFunction : rfd.findByProperty("function.id",                f.getId())) {            rfd.delete(roleFunction);        }        fd.delete(f);    }}


4、定义action方法实现与页面之间的交互工作

package com.myauth.functions.action;import java.util.List;import javax.servlet.http.HttpSession;import org.apache.struts2.ServletActionContext;import com.myauth.functions.entity.Function;import com.myauth.functions.service.IFunctionFacade;import com.myauth.module.entity.Module;import com.opensymphony.xwork2.Action;public class FunctionAction {    // 针对于页面的成员变量    private Function f;    private Module m;    private IFunctionFacade ff;    private List<Function> lf;    // 构造方法,用于对成员变量赋初值    public FunctionAction() {        f = new Function();        m = new Module();    }    // getter和setter方法    public Function getF() {        return f;    }    public void setF(Function f) {        this.f = f;    }    public Module getM() {        return m;    }    public void setM(Module m) {        this.m = m;    }    public IFunctionFacade getFf() {        return ff;    }    public void setFf(IFunctionFacade ff) {        this.ff = ff;    }    public List<Function> getLf() {        return lf;    }    public void setLf(List<Function> lf) {        this.lf = lf;    }    // 处理newFunction请求的方法    public String newFunction() {        // 将模块id从session中取出        HttpSession hs = ServletActionContext.getRequest().getSession();        ff.newFunction(f, (Integer) hs.getAttribute("mid"));        return Action.SUCCESS;    }    // 处理findFunction请求的方法    @SuppressWarnings("unchecked")    public String findFunction() {        // 将角色信息从session中取出        HttpSession hs = ServletActionContext.getRequest().getSession();        lf = ff.findFunction((List<Integer>) hs.getAttribute("role"),m);        return Action.SUCCESS;    }    // 处理removeFunction请求的方法    public String removeFunction() {        ff.removeFunction(f);        return Action.SUCCESS;    }    // 处理findSingleFunction请求的方法    public String findSingleFunction() {        f = ff.findSingleFunction(f);        return Action.SUCCESS;    }    // 处理modifyFunction请求的方法    public String modifyFunction() {        ff.modifyFunction(f);        return Action.SUCCESS;    }    // 处理findFByMId请求的方法    public String findFByMId() {        HttpSession hs = ServletActionContext.getRequest().getSession();        // 判断m是否为空        if (m == null || m.getId() == null) {            // 如果m为空将session中的mid值赋给m的id值            m.setId((Integer) hs.getAttribute("mid"));        } else {            // 将模块id做成session            hs.setAttribute("mid", m.getId());        }        lf = ff.findFByMId(m);        ServletActionContext.getRequest().setAttribute("FNo", lf.size());        return Action.SUCCESS;    }}


5、权限管理是一个菜单树的形式,下面是实现菜单树的页面代码

<%@ page contentType="text/html; charset=utf-8"%><%@ taglib prefix="s" uri="/struts-tags"%><html><head>    <title>功能树</title></head>    <body>        <s:fielderror></s:fielderror>        <table>            <s:iterator value="lf">                <tr>                    <td>                        <a href=<s:url action="%{url}"/> target="content">                            <h3><s:property value="functionname"/></h3>                        </a>                    </td>                </tr>            </s:iterator>        </table>        <a href="exit.action" target="content"><h4>退出登录</h4></a>    </body></html>


6、添加新的功能

<%@ page contentType="text/html; charset=utf-8"%><%@ taglib prefix="s" uri="/struts-tags"%><html>    <head>        <title>新增功能页</title>    </head>    <body>        <form action="newFunction.action" method="post">            <table width="700" height="400" border="0" align="center">                <tr>                    <td valign="top">                        <table height=28 cellSpacing=0 cellPadding=0 width="90%"                            align=center                            background="<%=request.getContextPath()%>/image/border/border1/topcenter.gif"                            border=0>                            <tbody>                                <tr id=cat>                                    <td vAlign=top align=left width=28 height=28>                                        <IMG height=28                                            src="<%=request.getContextPath()%>/image/border/border1/topleft.gif"                                            width=28 border=0>                                    </td>                                    <td width="189" height=28 align=left vAlign=center                                        background="<%=request.getContextPath()%>/image/border/border1/topbg.gif">                                        &nbsp;                                    </td>                                    <td vAlign=center align=left width=28>                                        <IMG height=28                                            src="<%=request.getContextPath()%>/image/border/border1/topend.gif"                                            width=19 border=0>                                    </td>                                    <td vAlign=top align=right width="157"></td>                                    <td vAlign=top align=right width=296 height=28>                                        <IMG height=28                                            src="<%=request.getContextPath()%>/image/border/border1/topright.gif"                                            width=296 border=0>                                    </td>                                </tr>                            </tbody>                        </table>                        <table cellSpacing=0 cellPadding=0 width="90%" align=center                            bgColor=#89959b border=0>                            <tbody>                                <tr>                                    <td>                                        <table cellSpacing=1 cellPadding=4 width="100%" border=0>                                            <tbody>                                                <tr vAlign="bottom" align="middle">                                                    <td                                                        background="<%=request.getContextPath()%>                                                        /image/border/border1/greenbarbg.gif"                                                        width="20%" height="30" colspan="2">                                                    </td>                                                </tr>                                                <tr align="center">                                                    <td onmouseover="this.bgColor='#ffffff'"                                                        onmouseout="this.bgColor='#f5f5f5'" align=left                                                        bgColor=#f5f5f5>                                                        <FONT face="verdana, arial, helvetica,宋体"> 功能名                                                     </td>                                                    <td onmouseover="this.bgColor='#ffffff'"                                                        onmouseout="this.bgColor='#f5f5f5'" align=left                                                        bgColor=#f5f5f5>                                                        <s:textfield name="f.functionname" theme="simple" />                                                    </td>                                                </tr>                                                <tr align="center">                                                    <td onmouseover="this.bgColor='#ffffff'"                                                        onmouseout="this.bgColor='#f5f5f5'" align=left                                                        bgColor=#f5f5f5>                                                        <FONT face="verdana, arial, helvetica,宋体"> 功能路径                                                     </td>                                                    <td onmouseover="this.bgColor='#ffffff'"                                                        onmouseout="this.bgColor='#f5f5f5'" align=left                                                        bgColor=#f5f5f5>                                                        <s:textfield name="f.url" theme="simple" />                                                    </td>                                                </tr>                                                <tr vAlign="bottom" align="right">                                                    <td                                                        background="<%=request.getContextPath()%>                                                        /image/border/border1/greenbarbg.gif"                                                        width="20%" height="30" colspan="2">                                                        <s:submit value="新增" theme="simple" />                                                        <s:reset value="重置" theme="simple" />                                                    </td>                                                </tr>                                            </tbody>                                        </table>                                    </td>                                </tr>                        </table>                        <table width="90%" height=23 border=0 align="center" cellPadding=0                            cellSpacing=0>                            <tbody>                                <tr>                                    <td vAlign=top align=left width=100 height=23>                                        <IMG height=23                                            src="<%=request.getContextPath()%>/image/border/border1/bottomleft.gif"                                            width=100>                                    </td>                                    <td width="100%"                                        background="<%=request.getContextPath()%>/image/border/border1/bottomcenter.gif"                                        height=23>                                        <IMG height=1                                            src="<%=request.getContextPath()%>/image/border/border1/clear.gif"                                            width="100%">                                    </td>                                    <td vAlign=top align=right width=100 height=23>                                        <IMG height=23                                            src="<%=request.getContextPath()%>/image/border/border1/bottomright.gif"                                            width=100 border=0>                                    </td>                                </tr>                            </tbody>                        </table>                    </td>                </tr>            </table>        </form>    </body></html>


7、修改功能页面

<%@ page contentType="text/html; charset=utf-8"%><%@ taglib prefix="s" uri="/struts-tags"%><html><head>    <title>修改功能页</title></head>    <body>        <form action="modifyFunction.action" method="post">        <table width="700" height="400" border="0" align="center">                <tr>                    <td valign="top">                        <table height=28 width="90%" align=center background="<%=request.getContextPath()%>/image/border/border1/topcenter.gif" border=0>                            <tbody>                                <tr id=cat>                                    <tr vAlign=top align=left width=28 height=28>                                        <img height=28 src="<%=request.getContextPath()%>/image/border/border1/topleft.gif" width=28 border=0>                                    </td>                                    <td width="189" height=28 align=left vAlign=center                                        background="<%=request.getContextPath()%>/image/border/border1/topbg.gif">                                        &nbsp;                                    </td>                                    <td vAlign=center align=left width=28>                                        <img height=28                                            src="<%=request.getContextPath()%>/image/border/border1/topend.gif"                                            width=19 border=0>                                    </td>                                    <td vAlign=top align=right width="157"></td>                                    <td vAlign=top align=right width=296 height=28>                                        <img height=28                                            src="<%=request.getContextPath()%>/image/border/border1/topright.gif"                                            width=296 border=0>                                    </td>                                </tr>                            </tbody>                        </table>                        <table cellSpacing=0 cellPadding=0 width="90%" align=center bgColor=#89959b border=0>                            <tbody>                                <tr>                                    <td>                                        <table cellSpacing=1 cellPadding=4 width="100%" border=0>                                            <tbody>                                                <tr vAlign="bottom" align="middle">                                                    <td                                                        background="<%=request.getContextPath()%>                                                        /image/border/border1/greenbarbg.gif"                                                        width="20%" height="30" colspan="2">                                                    </td>                                                </tr>                                                <tr align="center">                                                    <td onmouseover="this.bgColor='#ffffff'"                                                        onmouseout="this.bgColor='#f5f5f5'" align=left                                                        bgColor=#f5f5f5>                                                        <FONT face="verdana, arial, helvetica,宋体"> 功能序号                                                     </td>                                                    <td onmouseover="this.bgColor='#ffffff'"                                                        onmouseout="this.bgColor='#f5f5f5'" align=left                                                        bgColor=#f5f5f5>                                                        <s:textfield name="f.id" value="%{f.id}" theme="simple" readonly="true"/>                                                    </td>                                                </tr>                                                <tr align="center">                                                    <td onmouseover="this.bgColor='#ffffff'"                                                        onmouseout="this.bgColor='#f5f5f5'" align=left                                                        bgColor=#f5f5f5>                                                        <FONT face="verdana, arial, helvetica,宋体"> 所属模块id                                                     </td>                                                    <td onmouseover="this.bgColor='#ffffff'"                                                        onmouseout="this.bgColor='#f5f5f5'" align=left                                                        bgColor=#f5f5f5>                                                        <s:textfield name="f.module.id" value="%{f.module.id}" readonly="true" theme="simple"/>                                                    </td>                                                </tr>                                                <tr align="center">                                                    <td onmouseover="this.bgColor='#ffffff'"                                                        onmouseout="this.bgColor='#f5f5f5'" align=left                                                        bgColor=#f5f5f5>                                                        <FONT face="verdana, arial, helvetica,宋体"> 功能名                                                    </td>                                                    <td onmouseover="this.bgColor='#ffffff'"                                                        onmouseout="this.bgColor='#f5f5f5'" align=left                                                        bgColor=#f5f5f5>                                                        <s:textfield name="f.functionname" value="%{f.functionname}" theme="simple"/>                                                    </td>                                                </tr>                                                <tr align="center">                                                    <td onmouseover="this.bgColor='#ffffff'"                                                        onmouseout="this.bgColor='#f5f5f5'" align=left                                                        bgColor=#f5f5f5>                                                        <FONT face="verdana, arial, helvetica,宋体"> 功能路径                                                     </td>                                                    <td onmouseover="this.bgColor='#ffffff'"                                                        onmouseout="this.bgColor='#f5f5f5'" align=left                                                        bgColor=#f5f5f5>                                                        <s:textfield name="f.url" value="%{f.url}" theme="simple"/>                                                    </td>                                                </tr>                                                <tr vAlign="bottom" align="right">                                                    <td                                                        background="<%=request.getContextPath()%>                                                        /image/border/border1/greenbarbg.gif"                                                        width="20%" height="30" colspan="2">                                                        <s:submit value="修改" theme="simple" />                                                        <s:reset value="重置" theme="simple" />                                                    </td>                                                </tr>                                            </tbody>                                        </table>                                    </td>                                </tr>                        </table>                        <table width="90%" height=23 border=0 align="center" cellPadding=0                            cellSpacing=0>                            <tbody>                                <tr>                                    <td vAlign=top align=left width=100 height=23>                                        <IMG height=23                                            src="<%=request.getContextPath()%>/image/border/border1/bottomleft.gif"                                            width=100>                                    </td>                                    <td width="100%"                                        background="<%=request.getContextPath()%>/image/border/border1/bottomcenter.gif"                                        height=23>                                        <IMG height=1                                            src="<%=request.getContextPath()%>/image/border/border1/clear.gif"                                            width="100%">                                    </td>                                    <td vAlign=top align=right width=100 height=23>                                        <IMG height=23                                            src="<%=request.getContextPath()%>/image/border/border1/bottomright.gif"                                            width=100 border=0>                                    </td>                                </tr>                            </tbody>                        </table>                    </td>                </tr>            </table>        </form>    </body></html>


8、操作功能页

<%@ page contentType="text/html; charset=utf-8"%><%@ taglib prefix="s" uri="/struts-tags"%><html>    <head>        <title>操作功能页</title>    </head>    <body>        <table width="700" height="400" border="0" align="center">            <tr>                <td valign="top">                    <table height=28 width="90%" align=center                        background="<%=request.getContextPath()%>/image/border/border1/topcenter.gif"                        border=0>                        <tbody>                            <tr id=cat>                                <td vAlign=top align=left width=28 height=28>                                    <IMG height=28                                        src="<%=request.getContextPath()%>/image/border/border1/topleft.gif"                                        width=28 border=0>                                </td>                                <td width="189" height="28" align="left" vAlign="center"                                    background="<%=request.getContextPath()%>/image/border/border1/topbg.gif">                                    &nbsp;                                </td>                                <td vAlign=center align=left width=28>                                    <IMG height=28                                        src="<%=request.getContextPath()%>/image/border/border1/topend.gif"                                        width=19 border=0>                                </td>                                <td vAlign=top align=right width="157"></td>                                <td vAlign=top align=right width=296 height=28>                                    <IMG height=28                                        src="<%=request.getContextPath()%>/image/border/border1/topright.gif"                                        width=296 border=0>                                </td>                            </tr>                        </tbody>                    </table>                    <table cellSpacing=0 cellPadding=0 width="90%" align=center bgColor=#89959b border=0>                        <tbody>                            <tr>                                <td>                                    <table cellSpacing=1 cellPadding=4 width="100%" border=0>                                        <tbody>                                            <tr vAlign="bottom" align="center">                                                <td                                                    background="<%=request.getContextPath()%>                                                    /image/border/border1/greenbarbg.gif"                                                    width="20%">                                                    <div align="center">                                                        <FONT face="verdana, arial, helvetica,宋体" color=#ffffff><B>功能序号</B>                                                        </FONT>                                                    </div>                                                </td>                                                <td                                                    background="<%=request.getContextPath()%>                                                    /image/border/border1/greenbarbg.gif"                                                    width="20%">                                                    <div align="center">                                                        <FONT face="verdana, arial, helvetica,宋体" color=#ffffff><B>所属模块id</B>                                                        </FONT>                                                    </div>                                                </td>                                                <td                                                    background="<%=request.getContextPath()%>                                                    /image/border/border1/greenbarbg.gif"                                                    width="20%">                                                    <div align="center">                                                        <FONT face="verdana, arial, helvetica,宋体" color=#ffffff><B>url</B>                                                        </FONT>                                                    </div>                                                </td>                                                <td                                                    background="<%=request.getContextPath()%>                                                    /image/border/border1/greenbarbg.gif"                                                    width="20%">                                                    <div align="center">                                                        <FONT face="verdana, arial, helvetica,宋体" color=#ffffff><B>功能名</B>                                                        </FONT>                                                    </div>                                                </td>                                                <td                                                    background="<%=request.getContextPath()%>                                                    /image/border/border1/greenbarbg.gif"                                                    width="20%">                                                    <div align="center">                                                        <FONT face="verdana, arial, helvetica,宋体" color=#ffffff><B>删除操作</B>                                                        </FONT>                                                    </div>                                                </td>                                            </tr>                                            <s:iterator value="lf">                                                <tr align=center>                                                    <td onmouseover="this.bgColor='#ffffff'"                                                        onmouseout="this.bgColor='#f5f5f5'" align=left                                                        bgColor=#f5f5f5>                                                        <FONT face="verdana, arial, helvetica,宋体"><s:property                                                                value="id" />                                                    </td>                                                    <td onmouseover="this.bgColor='#ffffff'"                                                        onmouseout="this.bgColor='#f5f5f5'" align=left                                                        bgColor=#f5f5f5>                                                        <s:property value="module.id" />                                                    </td>                                                    <td onmouseover="this.bgColor='#ffffff'"                                                        onmouseout="this.bgColor='#f5f5f5'" align=left                                                        bgColor=#f5f5f5>                                                        <s:property value="url" />                                                    </td>                                                    <td onmouseover="this.bgColor='#ffffff'"                                                        onmouseout="this.bgColor='#f5f5f5'" align=left                                                        bgColor=#f5f5f5>                                                        <a                                                            href='<s:url action="findSingleFunction"><s:param name="f.id" value="id" /></s:url>'                                                            target="content"> <s:property value="functionname" />                                                        </a>                                                    </td>                                                    <td onmouseover="this.bgColor='#ffffff'"                                                        onmouseout="this.bgColor='#f5f5f5'" align=left                                                        bgColor=#f5f5f5>                                                        <a                                                            href='<s:url action="removeFunction"><s:param name="f.id" value="id" /></s:url>'                                                            target="content"> 删除 </a>                                                    </td>                                                </tr>                                            </s:iterator>                                            <tr id=cat>                                                <td align="center"                                                    background="<%=request.getContextPath()%>/image/border/border1/greenbarbg.gif"                                                    colSpan=5>                                                    <div align="left">                                                        <img                                                            src="<%=request.getContextPath()%>/image/border/border1/radio.gif"                                                            width="22" height="18" border="0" align="absmiddle">                                                        <a                                                            href='<%=request.getContextPath()%>/page/functions/newFunction.jsp'                                                            target="content">新增</a>                                                        <s:if test="#request.FNo==0">                                                            <img                                                                src="<%=request.getContextPath()%>/image/border/border1/radio.gif"                                                                width="22" height="18" border="0" align="absmiddle">                                                            <a                                                                href='<s:url action="removeModule"><s:param name="m.id" value="m.id" /></s:url>'                                                                target="content"> 删除所属模块</a>                                                        </s:if>                                                    </div>                                                </td>                                            </tr>                                        </tbody>                                    </table>                                </td>                            </tr>                    </table>                    <table width="90%" height=23 border=0 align="center" cellPadding=0                        cellSpacing=0>                        <tbody>                            <tr>                                <td vAlign=top align=left width=100 height=23>                                    <IMG height=23                                        src="<%=request.getContextPath()%>/image/border/border1/bottomleft.gif"                                        width=100>                                </td>                                <td width="100%"                                    background="<%=request.getContextPath()%>/image/border/border1/bottomcenter.gif"                                    height=23>                                    <IMG height=1                                        src="<%=request.getContextPath()%>/image/border/border1/clear.gif"                                        width="100%">                                </td>                                <td vAlign=top align=right width=100 height=23>                                    <IMG height=23                                        src="<%=request.getContextPath()%>/image/border/border1/bottomright.gif"                                        width=100 border=0>                                </td>                            </tr>                        </tbody>                    </table>                </td>            </tr>        </table>    </body></html>

 

七、总结

以上只是功能模块的代码,还有角色、用户、用户角色。角色权限等模块,这些也就仅仅是数据的增删改查操作,只要大家用心的去写一下就可以了。

不管是怎样的权限管理系统远远要比这个复杂,这里只是为了给大家提供功能模块的思维,仅供大家参考,详细的实现有兴趣的可以找我~我会详细的讲解。

本人也是菜鸟一枚,最后希望大家对我支持~~谢谢!

原创粉丝点击