员工管理系统————员工管理模块

1.分析

  当点击左边用户管理的超链接时,右边的iframe显示所有员工的信息。如图:

2.步骤

  a.在接口中声明获取所有员工的方法

  b.实现接口中的方法;

  c.调用dao获取数据中所有员工的数据

  d.请求共享数据

  e.请求转发到emp.jsp

3.代码

a:

IEmpDAO.java

public interface IEmpDAO {
    /*声明获取所有员工方法*/
    List<Map<String,Object>> getAllEmp();
}

b:

EmpDAOImpl.java

/*实现接口中的方法*/
public class EmpDAOImpl implements IEmpDAO{
    /*获得所有的员工信息,多表联查*/
    @Override
    public List<Map<String, Object>> getAllEmp() {
        String sql = "select e.id,e.name,e.telephone,e.hiredate,e.state,d.name dname,r.name rname from employee e INNER JOIN department  d on e.deptID = d.id INNER JOIN role r on e.roleID = r.id";
        return DBUtil.executeQuery(sql);
    }
}

c,d,e:

EmployeeServlet.java

@WebServlet("/emp")
public class EmployeeServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        /*获得数据库中所有数据*/
        IEmpDAO dao=new EmpDAOImpl();
        List<Map<String, Object>> allEmp = dao.getAllEmp();
        /*请求共享数据*/
        req.setAttribute("allEmp",allEmp);
        /*请求转发给某个jsp*/
        req.getRequestDispatcher("/emp.jsp").forward(req,resp);
    }
}

emp.jsp:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <table border="1px" cellspacing="0" width="95%" align="center">
        <tr>
            <th>员工编号</th>
            <th>员工姓名</th>
            <th>员工电话</th>
            <th>入职时间</th>
            <th>员工部门</th>
            <th>员工角色</th>
            <th>员工状态</th>
            <th>员工操作</th>
        </tr>
        <c:forEach items="${allEmp}" var="emp">
            <tr>
                <th>${emp.id}</th>
                <th>${emp.name}</th>
                <th>${emp.telephone}</th>
                <th>${emp.hiredate}</th>
                <th>${emp.dname}</th>
                <th>${emp.rname}</th>
                <th>${emp.state==1?"在职":"离职"}</th>
                <th><a >删除</a></th>
            </tr>
        </c:forEach>

    </table>
</body>
</html>

main.jsp:

 

转载于:https://www.cnblogs.com/duguangming/p/10725566.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值