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


    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:

  • 相关阅读:
    python-Web-django-路由保护
    python-Web-django-图表统计
    python-linux-集群nginx
    python-Web-数据库-oracle
    python-Web-数据库-mysql
    python-爬虫-scrapy
    Educational Codeforces Round 90 (Rated for Div. 2) A~C
    leetcode周赛192
    Codeforces Round #597 (Div. 2) C dp
    Codeforces Round #645 (Div. 2) A~D
  • 原文地址:https://www.cnblogs.com/duguangming/p/10725566.html
Copyright © 2020-2023  润新知