【计理01组38号】SSM 搭建简易人事管理系统


需求分析

系统功能结构

整个系统包含上述的几个模块,每个模块又包括多个功能:

  1. 系统管理:添加管理员、删除管理员、修改管理员和查询管理员(全部查询和按用户名模糊查询)
  2. 部门管理:添加部门、删除部门、修改部门和查询部门(全部查询和按部门名称模糊查询)
  1. 职位管理:添加职位、删除职位、修改职位和查询职位(全部查询和按职位名称模糊查询)
  2. 员工管理:添加员工、删除员工、修改员工和查询员工(全部查询和按员工编号、员工姓名、部门、职位和性别模糊查询)
  1. 公告管理:添加公告、删除公告、修改公告和查询公告(全部查询和按公告标题模糊查询)

软件设计

开发技术

  • Java EE 架构:SSM(Spring + Spring MVC + MyBatis)框架
  • 表现层技术:JSP
  • 前端框架:easyUI
  • 项目管理工具:Maven
  • 数据库:MySQL

系统架构

本系统采用的是 Java EE 分层结构:

  • 表现层:JSP 页面
  • MVC 控制器层:Spring MVC 技术,由一系列控制器组成。
  • 业务逻辑层:Spring 技术,由一系列的业务逻辑对象组成。
  • DAO 层:MyBatis 框架,由一系列的 DAO 组件组成,这些 DAO 实现了对数据库的创建、查询、更新和删除(CRUD)等原子操作。
  • Domain Object 层:由一系列的 POJO(Plain Old Java Object,即普通的、传统的 Java 对象)组成,是一些简单的 Java Bean 类。
  • 数据库:MySQL 数据库,存储持久化数据。

预期效果

登录页面:

系统主页:

功能模块页面:

代码实现

controller

AdminController.java

package com.shiyanlou.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.shiyanlou.domain.Admin;
import com.shiyanlou.service.AdminService;
import com.shiyanlou.util.ResponseUtil;

/**类中的所有响应方法都被映射到 /admin 路径下
 *
 * @author shiyanlou
 *
 */
@Controller
@RequestMapping("/admin")
public class AdminController {

    // 自动注入 adminService
    @Autowired
    private AdminService adminService;

    /** 处理登录请求
     *
     * @param admin
     * @param request
     * @param session
     * @return
     */
    @RequestMapping("/login")
    public String login(Admin admin, HttpServletRequest request,
            HttpSession session) {
        Admin resultAdmin = adminService.login(admin);
        // 如果该登录的管理员用户名或密码错误返回错误信息
        if (resultAdmin == null) {
            request.setAttribute("admin", admin);
            request.setAttribute("errorMsg",
                    "Please check your username and password!");
            return "login";
        } else {
            // 登录成功, Session 保存该管理员的信息
            session.setAttribute("currentAdmin", resultAdmin);
            session.setAttribute("username", resultAdmin.getUsername());
            return "redirect:main";
        }
    }

    /**处理跳转至主页请求
     *
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping(value="/main")
    public String test(Model model) throws Exception{
        return "home_page";
    }

    /**处理查询管理员请求
     *
     * @param admin
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping("/list")
    public String list(Admin admin, HttpServletResponse response)
            throws Exception {
        Map map = new HashMap();
        // 判断查询条件是否为空,如果是,对条件做数据库模糊查询的处理
        if (admin.getUsername() != null
                && !"".equals(admin.getUsername().trim())) {
            map.put("username", "%" + admin.getUsername() + "%");
        }
        List adminList = adminService.findAdmins(map);
        Integer total = adminService.getCount(map);
        // 将数据以 JSON 格式返回前端
        JSONObject result = new JSONObject();
        JSONArray jsonArray = JSONArray.fromObject(adminList);
        result.put("rows", jsonArray);
        result.put("total", total);
        ResponseUtil.write(response, result);
        return null;
    }

    /**处理保存管理员请求
     *
     * @param admin
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping("/save")
    public String save(Admin admin, HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        int resultTotal = 0;
        // 如果 id 不为空,则添加管理员,否则修改管理员
        if (admin.getId() == null){
            resultTotal = adminService.addAdmin(admin);
        }else{
            resultTotal = adminService.updateAdmin(admin);
        }
        JSONObject result = new JSONObject();
        if (resultTotal > 0) {
            result.put("success", true);
        } else {
            result.put("success", false);
        }
        ResponseUtil.write(response, result);
        return null;
    }

    /** 处理删除管理员请求
     *
     * @param ids
     * @param response
     * @param session
     * @return
     * @throws Exception
     */
    @RequestMapping("/delete")
    public String delete(@RequestParam(value = "ids") String ids,
            HttpServletResponse response, HttpSession session) throws Exception {
        JSONObject result = new JSONObject();
        // 将要删除的管理员的 id 进行处理
        String[] idsStr = ids.split(",");
        for (int i = 0; i < idsStr.length; i++) {
            // 不能删除超级管理员(superadmin) 和当前登录的管理员
            if (idsStr[i].equals("1")||idsStr[i].equals(((Admin)session.getAttribute("currentAdmin")).getId().toString())){
                result.put("success", false);
                continue;
            }else{
                adminService.deleteAdmin(Integer.parseInt(idsStr[i]));
                result.put("success", true);
            }
        }
        ResponseUtil.write(response, result);
        return null;
    }

    /**处理退出请求
     *
     * @param session
     * @return
     * @throws Exception
     */
    @RequestMapping("/logout")
    public String logout(HttpSession session) throws Exception {
        //清除session里的数据
        session.invalidate();
        return "redirect:/login.jsp";
    }
}

DeptController.java

package com.shiyanlou.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shiyanlou.domain.Department;
import com.shiyanlou.service.DepartmentService;
import com.shiyanlou.util.ResponseUtil;

/**类中的所有响应方法都被映射到 /dept 路径下
 *
 * @author shiyanlou
 *
 */
@Controller
@RequestMapping("/dept")
public class DeptController {

    // 自动注入 departmentService
    @Autowired
    private DepartmentService departmentService;

    /**处理查询部门请求
     *
     * @param department
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping("/list")
    public String list(Department department, HttpServletResponse response)
            throws Exception {
        Map map = new HashMap();
        // 判断查询条件是否为空,如果是,对条件做数据库模糊查询的处理
        if (department.getName() != null
                && !"".equals(department.getName().trim())) {
            map.put("name", "%" + department.getName() + "%");
        }
        List deptList = departmentService.findDepartments(map);
        Integer total = departmentService.getCount(map);
        JSONObject result = new JSONObject();
        JSONArray jsonArray = JSONArray.fromObject(deptList);
        result.put("rows", jsonArray);
        result.put("total", total);
        ResponseUtil.write(response, result);
        return null;
    }

    /**处理保存部门请求
     *
     * @param department
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping("/save")
    public String save(Department department, HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        int resultTotal = 0;
        // 如果 id 不为空,则添加部门,否则修改部门
        if (department.getId() == null)
            resultTotal = departmentService.addDepartment(department);
        else
            resultTotal = departmentService.updateDepartment(department);
        JSONObject result = new JSONObject();
        if (resultTotal > 0) {
            result.put("success", true);
        } else {
            result.put("success", false);
        }
        ResponseUtil.write(response, result);
        return null;
    }

    /**处理删除部门请求
     *
     * @param ids
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping("/delete")
    public String delete(@RequestParam(value = "ids") String ids,
            HttpServletResponse response) throws Exception {
        JSONObject result = new JSONObject();
        // 将要删除的部门的 id 进行处理
        String[] idsStr = ids.split(",");
        for (int i = 0; i < idsStr.length; i++) {
            // 捕获 service 层抛出的异常,如果捕获到则置 success 值为 false,返回给前端
            try {
                departmentService.deleteDepartment(Integer.parseInt(idsStr[i]));
                result.put("success", true);
            } catch (Exception e) {
                result.put("success", false);
            }
        }
        ResponseUtil.write(response, result);
        return null;
    }

    /**处理获得部门 id 与 name 请求,用于前端 easyUI combobox 的显示
     *
     * @param request
     * @return
     */
    @RequestMapping("/getcombobox")
    @ResponseBody
    public JSONArray getDept(HttpServletRequest request) {
        Map map = new HashMap();
        List deptList = departmentService.findDepartments(map);
        List> list = new ArrayList>();
        for (Department dept : deptList) {
            Map result = new HashMap();
            result.put("id", dept.getId());
            result.put("name", dept.getName());
            list.add(result);
        }
        // 返回 JSON
        JSONArray jsonArray = JSONArray.fromObject(list);
        return jsonArray;
    }
}

EmployeeController.java

package com.shiyanlou.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.shiyanlou.domain.Employee;
import com.shiyanlou.domain.Post;
import com.shiyanlou.service.EmployeeService;
import com.shiyanlou.util.IntegrateObject;
import com.shiyanlou.util.JsonDateValueProcessor;
import com.shiyanlou.util.ResponseUtil;

/**类中的所有响应方法都被映射到 /empl 路径下
 *
 * @author shiyanlou
 *
 */
@Controller
@RequestMapping("/empl")
public class EmployeeController {

    // 自动注入 employeeService
    @Autowired
    private EmployeeService employeeService;

    /**处理查询员工请求
     *
     * @param employee
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping("/list")
    public String list(Employee employee, HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        Map map = new HashMap();
        // 判断查询条件是否为空,如果是,对条件做数据库模糊查询的处理。(因为id和性别属于精确数字,所以不做模糊查询处理)
        if (employee.getId() != null && !"".equals(employee.getId().trim())) {
            map.put("id",  employee.getId());
        }
        if (employee.getName() != null && !"".equals(employee.getName().trim())) {
            map.put("name", "%" + employee.getName() + "%");
        }
        if (employee.getSex() != null && !"".equals(employee.getSex().trim())) {
            map.put("sex",  employee.getSex() );
        }
        if (employee.getDepartment() != null) {
            if (employee.getDepartment().getName() != null
                    && !"".equals(employee.getDepartment().getName().trim())) {
                map.put("department_name", "%"
                        + employee.getDepartment().getName() + "%");
            }
        }
        if (employee.getPosition() != null) {
            if (employee.getPosition().getName() != null
                    && !"".equals(employee.getPosition().getName().trim())) {
                map.put("position_name", "%" + employee.getPosition().getName()
                        + "%");
            }
        }
        List postList = employeeService.findEmployees(map);
        Integer total = employeeService.getCount(map);
        // 处理日期使之能在 easyUI 的 datagrid 中正常显示
        JsonConfig jsonConfig = new JsonConfig();
        jsonConfig.registerJsonValueProcessor(Date.class,
                new JsonDateValueProcessor());

        JSONObject result = new JSONObject();
        JSONArray jsonArray = JSONArray.fromObject(postList, jsonConfig);
        result.put("rows", jsonArray);
        result.put("total", total);
        ResponseUtil.write(response, result);
        return null;
    }

    /**处理保存员工请求
     *
     * @param dept_id
     * @param pos_id
     * @param updateFlag
     * @param employee
     * @param request
     * @param response
     * @param session
     * @return
     * @throws Exception
     */
    @RequestMapping("/save")
    public String save(@RequestParam("dept_id") Integer dept_id,
            @RequestParam("pos_id") Integer pos_id, @RequestParam("updateFlag") String updateFlag, Employee employee,
            HttpServletRequest request, HttpServletResponse response,
            HttpSession session) throws Exception {
        int resultTotal = 0;
        // 完成 Department 和 Position 在 Employee 中的关联映射
        IntegrateObject.genericAssociation(dept_id, pos_id, employee);

        JSONObject result = new JSONObject();
        // 根据 updateFlag 的值,判断保存方式,如果值为 no,则添加员工,如果值为 yes,则修改员工
        if (updateFlag.equals("no")){
            // 捕获 service 层插入时主键重复抛出的异常,如果捕获到则置 success 值为 false,返回给前端
            try {
                resultTotal = employeeService.addEmployee(employee);
                if (resultTotal > 0) {
                    result.put("success", true);
                } else {
                    result.put("success", false);
                }
            } catch (Exception e) {
                result.put("success", false);
            }
        }else if(updateFlag.equals("yes")){
            resultTotal = employeeService.updateEmployee(employee);
            if (resultTotal > 0) {
                result.put("success", true);
            } else {
                result.put("success", false);
            }
        }
        ResponseUtil.write(response, result);
        return null;
    }

    /**处理删除员工请求
     *
     * @param ids
     * @param response
     * @param session
     * @return
     * @throws Exception
     */
    @RequestMapping("/delete")
    public String delete(@RequestParam(value = "ids") String ids,
            HttpServletResponse response, HttpSession session) throws Exception {
        JSONObject result = new JSONObject();
        // 将要删除的部门的 id 进行处理
        String[] idsStr = ids.split(",");
        for (int i = 0; i < idsStr.length; i++) {
            employeeService.deleteEmployee(idsStr[i]);

        }
        result.put("success", true);
        ResponseUtil.write(response, result);
        return null;
    }

    /**springmvc 日期绑定
     *
     * @param binder
     */
    @InitBinder
    public void initBinder(WebDataBinder binder) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        CustomDateEditor editor = new CustomDateEditor(dateFormat, true);
        binder.registerCustomEditor(Date.class, editor);
    }

}

PositionController.java

package com.shiyanlou.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shiyanlou.domain.Position;
import com.shiyanlou.service.PositionService;
import com.shiyanlou.util.ResponseUtil;

/**类中的所有响应方法都被映射到 /position 路径下
 *
 * @author shiyanlou
 *
 */
@Controller
@RequestMapping("/position")
public class PositionController {

    // 自动注入 positionService
    @Autowired
    private PositionService positionService;

    /**处理查询职位请求
     *
     * @param position
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping("/list")
    public String list(Position position, HttpServletResponse response)
            throws Exception {
        Map map = new HashMap();
        // 判断查询条件是否为空,如果是,对条件做数据库模糊查询的处理
        if (position.getName() != null
                && !"".equals(position.getName().trim())) {
            map.put("name", "%" + position.getName() + "%");
        }
        List dpositionList = positionService.findPositions(map);
        Integer total = positionService.getCount(map);
        JSONObject result = new JSONObject();
        JSONArray jsonArray = JSONArray.fromObject(dpositionList);
        result.put("rows", jsonArray);
        result.put("total", total);
        ResponseUtil.write(response, result);
        return null;
    }

    /**处理保存职位请求
     *
     * @param position
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping("/save")
    public String save(Position position, HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        int resultTotal = 0;
        // 如果 id 不为空,则添加职位,否则修改职位
        if (position.getId() == null){
            resultTotal = positionService.addPosition(position);
        }else{
            resultTotal = positionService.updatePosition(position);
        }
        JSONObject result = new JSONObject();
        if (resultTotal > 0) {
            result.put("success", true);
        } else {
            result.put("success", false);
        }
        ResponseUtil.write(response, result);
        return null;
    }

    /**处理删除职位请求
     *
     * @param ids
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping("/delete")
    public String delete(@RequestParam(value = "ids") String ids,
            HttpServletResponse response) throws Exception {
        JSONObject result = new JSONObject();
        // 将要删除的部门的 id 进行处理
        String[] idsStr = ids.split(",");
        for (int i = 0; i < idsStr.length; i++) {
            // 捕获 service 层抛出的异常,如果捕获到则置 success 值为 false,返回给前端
            try {
                positionService.deletePosition(Integer.parseInt(idsStr[i]));
                result.put("success", true);
            } catch (Exception e) {
                result.put("success", false);
            }
        }
        ResponseUtil.write(response, result);
        return null;
    }

    /**处理获得职位 id 与 name 请求,用于前端 easyUI combobox 的显示
     *
     * @param request
     * @return
     */
    @RequestMapping("/getcombobox")
    @ResponseBody
    public JSONArray getPos(HttpServletRequest request) {
        Map map = new HashMap();
        List posList = positionService.findPositions(map);
        List> list = new ArrayList>();
        for (Position pos : posList) {
            Map result = new HashMap();
            result.put("id", pos.getId());
            result.put("name", pos.getName());
            list.add(result);
        }
        // 返回 JSON
        JSONArray jsonArray = JSONArray.fromObject(list);
        return jsonArray;
    }
}

PostController.java

package com.shiyanlou.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.shiyanlou.domain.Admin;
import com.shiyanlou.domain.Post;
import com.shiyanlou.service.PostService;
import com.shiyanlou.util.DateUtil;
import com.shiyanlou.util.JsonDateValueProcessor;
import com.shiyanlou.util.ResponseUtil;

/**类中的所有响应方法都被映射到 /post 路径下
 *
 * @author shiyanlou
 *
 */
@Controller
@RequestMapping("/post")
public class PostController {
    // 自动注入 postService
    @Autowired
    private PostService postService;

    /**处理查询公告请求
     *
     * @param post
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping("/list")
    public String list(Post post, HttpServletResponse response)
            throws Exception {
        Map map = new HashMap();
        // 判断查询条件是否为空,如果是,对条件做数据库模糊查询的处理
        if (post.getTitle() != null && !"".equals(post.getTitle().trim())) {
            map.put("title", "%" + post.getTitle() + "%");
        }
        List postList = postService.findPosts(map);
        Integer total = postService.getCount(map);

        // 处理日期使之能在 easyUI 的 datagrid 中正常显示
        JsonConfig jsonConfig = new JsonConfig();
        jsonConfig.registerJsonValueProcessor(Date.class,
                new JsonDateValueProcessor());
        // 将数据以 JSON 格式返回前端
        JSONObject result = new JSONObject();
        JSONArray jsonArray = JSONArray.fromObject(postList, jsonConfig);
        result.put("rows", jsonArray);
        result.put("total", total);
        ResponseUtil.write(response, result);
        return null;
    }

    /**处理保存公告请求
     *
     * @param post
     * @param request
     * @param response
     * @param session
     * @return
     * @throws Exception
     */
    @RequestMapping("/save")
    public String save(Post post, HttpServletRequest request,
            HttpServletResponse response, HttpSession session) throws Exception {
        Admin admin = (Admin)session.getAttribute("currentAdmin");
        post.setAdmin(admin);
        post.setDate(DateUtil.getDate());
        int resultTotal = 0;
        // 如果 id 不为空,则添加公告,否则修改公告
        if (post.getId() == null){
            resultTotal = postService.addPost(post);
        }else{
            resultTotal = postService.updatePost(post);
        }
        JSONObject result = new JSONObject();
        if (resultTotal > 0) {
            result.put("success", true);
        } else {
            result.put("success", false);
        }
        ResponseUtil.write(response, result);
        return null;
    }

    /**处理删除公告请求
     *
     * @param ids
     * @param response
     * @param session
     * @return
     * @throws Exception
     */
    @RequestMapping("/delete")
    public String delete(@RequestParam(value = "ids") String ids,
            HttpServletResponse response, HttpSession session) throws Exception {
        JSONObject result = new JSONObject();
        // 将要删除的公告的 id 进行处理
        String[] idsStr = ids.split(",");
        for (int i = 0; i < idsStr.length; i++) {
            postService.deletePost(Integer.parseInt(idsStr[i]));

        }
        result.put("success", true);
        ResponseUtil.write(response, result);
        return null;
    }

    /**处理根据 id 查询公告请求
     *
     * @param id
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping("/getById")
    public String getById(@RequestParam(value = "id") Integer id,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        Post post = postService.getPostById(id);
        request.setAttribute("postContent", post.getContent());
        return "postContent";
    }
}

dao

AdminDao.java

package com.shiyanlou.dao;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.shiyanlou.domain.Admin;

@Repository
public interface AdminDao {

    /** 登录
     *
     * @param admin
     * @return
     */
    public Admin login(Admin admin);

    /** 根据条件查询管理员
     *
     * @param map
     * @return
     */
    public List findAdmins(Map map);

    /** 根据条件查询管理员人数
     *
     * @param map
     * @return
     */
    public Integer getCount(Map map);

    /** 添加管理员
     *
     * @param admin
     * @return
     */
    public Integer addAdmin(Admin admin);

    /** 修改管理员
     *
     * @param admin
     * @return
     */
    public Integer updateAdmin(Admin admin);

    /** 删除管理员
     *
     * @param id
     * @return
     */
    public Integer deleteAdmin(Integer id);
}

DepartmentDao.java

package com.shiyanlou.dao;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.shiyanlou.domain.Department;

@Repository
public interface DepartmentDao {

    /** 根据条件查询部门
     *
     * @param map
     * @return
     */
    public List findDepartments(Map map);

    /** 根据条件查询部门数量
     *
     * @param map
     * @return
     */
    public Integer getCount(Map map);

    /** 添加部门
     *
     * @param department
     * @return
     */
    public Integer addDepartment(Department department);

    /** 修改部门
     *
     * @param department
     * @return
     */
    public Integer updateDepartment(Department department);

    /** 删除部门
     *
     * @param id
     * @return
     */
    public Integer deleteDepartment(Integer id);

}

EmployeeDao.java

package com.shiyanlou.dao;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.shiyanlou.domain.Employee;
import com.shiyanlou.domain.Post;

@Repository
public interface EmployeeDao {

    /** 根据条件查询员工
     *
     * @param map
     * @return
     */
    public ListfindEmployees(Map map);

    /** 根据条件查询员工数量
     *
     * @param map
     * @return
     */
    public Integer getCount(Map map);

    /** 添加员工
     *
     * @param employee
     * @return
     */
    public Integer addEmployee(Employee employee);

    /** 修改员工
     *
     * @param employee
     * @return
     */
    public Integer updateEmployee(Employee employee);

    /** 删除员工
     *
     * @param id
     * @return
     */
    public Integer deleteEmployee(String id);
}

PositionDao.java

package com.shiyanlou.dao;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.shiyanlou.domain.Position;

@Repository
public interface PositionDao {

    /** 根据条件查询职位
     *
     * @param map
     * @return
     */
    public List findPositions(Map map);

    /** 根据条件查询职位数量
     *
     * @param map
     * @return
     */
    public Integer getCount(Map map);

    /** 添加职位
     *
     * @param position
     * @return
     */
    public Integer addPosition(Position position);

    /** 修改职位
     *
     * @param position
     * @return
     */
    public Integer updatePosition(Position position);

    /** 删除职位
     *
     * @param id
     * @return
     */
    public Integer deletePosition(Integer id);
}

PostDao.java

package com.shiyanlou.dao;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.shiyanlou.domain.Post;

@Repository
public interface PostDao {
    /** 根据条件查询公告
     *
     * @return
     */
    public ListfindPosts(Map map);

    /** 根据条件查询公告数量
     *
     * @param map
     * @return
     */
    public Integer getCount(Map map);

    /** 添加公告
     *
     * @param post
     * @return
     */
    public Integer addPost(Post post);

    /** 修改公告
     *
     * @param post
     * @return
     */
    public Integer updatePost(Post post);

    /** 删除公告
     *
     * @param id
     * @return
     */
    public Integer deletePost(Integer id);

    /** 根据 ID 查询公告信息
     *
     * @param id
     * @return
     */
    public Post getPostById(Integer id);
}

domain

Admin.java

package com.shiyanlou.domain;

import java.io.Serializable;

public class Admin implements Serializable {

    private static final long serialVersionUID = 1L;

    private Integer id;  // 管理员编号
    private String username;  // 用户名
    private String password;  // 密码
    private String role_name;   // 管理员角色

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getRole_name() {
        return role_name;
    }

    public void setRole_name(String role_name) {
        this.role_name = role_name;
    }

    @Override
    public String toString() {
        return "Admin:[id=" + id + ",username=" + username + ",password="
                + password + ",role_name=" + role_name + "]";
    }
}

Department.java

package com.shiyanlou.domain;

import java.io.Serializable;

public class Department implements Serializable {

    private static final long serialVersionUID = 1L;

    private Integer id;  // 部门编号
    private String name;  // 名称
    private String description;  // 描述

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Override
    public String toString() {
        return "Department:[id=" + id + ",name=" + name + ",description="
                + description + "]";
    }
}

Employee.java

package com.shiyanlou.domain;

import java.io.Serializable;
import java.util.Date;

public class Employee implements Serializable {

    private static final long serialVersionUID = 1L;

    private String id;  // 员工编号
    private String name;  // 姓名
    private String sex;  // 性别
    private String phone;  // 电话
    private String email;  // 邮箱
    private String address;  // 地址
    private String education;  // 学历
    private Date birthday;  // 生日
    private Department department;  // 部门
    private Position position;  // 职位

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getEducation() {
        return education;
    }

    public void setEducation(String education) {
        this.education = education;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public Department getDepartment() {
        return department;
    }

    public void setDepartment(Department department) {
        this.department = department;
    }

    public Position getPosition() {
        return position;
    }

    public void setPosition(Position position) {
        this.position = position;
    }

    @Override
    public String toString() {
        return "Employee:[id=" + id + ",name=" + name + ",sex=" + sex
                + ",phone=" + phone + ",email=" + email + ",address=" + address
                + ",education=" + education + ",birthday=" + birthday
                + ",department=" + department + ",position=" + position + "]";
    }

}

Position.java

package com.shiyanlou.domain;

import java.io.Serializable;

public class Position implements Serializable {

    private static final long serialVersionUID = 1L;

    private Integer id;  // 职位编号
    private String name;  // 名称
    private String description;  // 描述

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Override
    public String toString() {
        return "Position:[id=" + id + ",name=" + name + ",description="
                + description + "]";
    }
}

Post.java

package com.shiyanlou.domain;

import java.io.Serializable;
import java.util.Date;

public class Post implements Serializable {

    private static final long serialVersionUID = 1L;

    private Integer id;  // 公告编号
    private String title;  // 标题
    private String content;  // 内容
    private Admin admin;  // 发布人
    private Date date;  // 发布日期

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public Admin getAdmin() {
        return admin;
    }

    public void setAdmin(Admin admin) {
        this.admin = admin;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    @Override
    public String toString() {
        return "Post:[id=" + id + ",title=" + title + ",content=" + content
                + ",admin=" + admin + ",date=" + date + "]";
    }
}

interceptor

package com.shiyanlou.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class LoginInterceptor implements HandlerInterceptor {
    // 不拦截 "/login" 请求
    private static final String[] IGNORE_URI = { "/login" };

    @Override
    public void afterCompletion(HttpServletRequest arg0,
            HttpServletResponse arg1, Object arg2, Exception arg3)
            throws Exception {

    }

    @Override
    public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1,
            Object arg2, ModelAndView arg3) throws Exception {

    }

    // 该方法将在 Controller 处理前进行调用
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
            Object handler) throws Exception {
        // flag 表示是否登录
        boolean flag = false;
        // 获取请求的 URL
        String url = request.getServletPath();
        for (String s : IGNORE_URI) {
            if (url.contains(s)) {
                flag = true;
                break;
            }
        }
        if (!flag) {
            // 获取 Session 并判断是否登录
            String username = (String) request.getSession().getAttribute(
                    "username");
            if (username == null) {
                request.setAttribute("message", "Please log in first!");
                // 如果未登录,进行拦截,跳转到登录页面
                request.getRequestDispatcher("/login.jsp")
                        .forward(request, response);
            } else {
                flag = true;
            }
        }
        return flag;
    }

}

service

AdminServiceImpl.java

package com.shiyanlou.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.shiyanlou.dao.AdminDao;
import com.shiyanlou.domain.Admin;
import com.shiyanlou.service.AdminService;

@Transactional
@Service("adminService")
public class AdminServiceImpl implements AdminService {

    @Autowired
    private AdminDao adminDao;

    public Admin login(Admin admin) {
        return adminDao.login(admin);
    }

    public List findAdmins(Map map) {

        return adminDao.findAdmins(map);
    }

    public Integer getCount(Map map) {

        return adminDao.getCount(map);
    }

    public Integer addAdmin(Admin admin) {

        return adminDao.addAdmin(admin);
    }

    public Integer updateAdmin(Admin admin) {

        return adminDao.updateAdmin(admin);
    }

    public Integer deleteAdmin(Integer id) {

        return adminDao.deleteAdmin(id);
    }

}

DepartmentServiceImpl.java

package com.shiyanlou.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.shiyanlou.dao.DepartmentDao;
import com.shiyanlou.domain.Department;
import com.shiyanlou.service.DepartmentService;

@Transactional
@Service("departmentService")
public class DepartmentServiceImpl implements DepartmentService {

    @Autowired
    private DepartmentDao departmentDao;

    public List findDepartments(Map map) {

        return departmentDao.findDepartments(map);
    }

    public Integer getCount(Map map) {

        return departmentDao.getCount(map);
    }

    public Integer addDepartment(Department department) {

        return departmentDao.addDepartment(department);
    }

    public Integer updateDepartment(Department department) {

        return departmentDao.updateDepartment(department);
    }

    public Integer deleteDepartment(Integer id) {
        Integer flag = null;
        try {
            flag = departmentDao.deleteDepartment(id);
        } catch (Exception e) {
            throw new RuntimeException();
        }

        return flag;
    }
}

EmployeeServiceImpl.java

package com.shiyanlou.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.shiyanlou.dao.EmployeeDao;
import com.shiyanlou.domain.Employee;
import com.shiyanlou.domain.Post;
import com.shiyanlou.service.EmployeeService;

@Transactional
@Service("employeeService")
public class EmployeeServiceImpl implements EmployeeService {

    @Autowired
    private EmployeeDao employeeDao;

    public List findEmployees(Map map) {

        return employeeDao.findEmployees(map);
    }

    public Integer getCount(Map map) {

        return employeeDao.getCount(map);
    }

    public Integer addEmployee(Employee employee) {
        Integer flag = null;
        try {
            //如果插入主键重复,抛出异常
            flag =  employeeDao.addEmployee(employee);
        } catch (Exception e) {
            throw new RuntimeException();
        }

        return flag;
    }

    public Integer updateEmployee(Employee employee) {

        return employeeDao.updateEmployee(employee);
    }

    public Integer deleteEmployee(String id) {

        return employeeDao.deleteEmployee(id);
    }

}

PositionServiceImpl.java

package com.shiyanlou.service.impl;

import java.util.List;
import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.shiyanlou.dao.PositionDao;
import com.shiyanlou.domain.Position;
import com.shiyanlou.service.PositionService;

@Transactional
@Service("positionService")
public class PositionServiceImpl implements PositionService {

    @Autowired
    private PositionDao positionDao;

    public List findPositions(Map map) {

        return positionDao.findPositions(map);
    }

    public Integer getCount(Map map) {

        return positionDao.getCount(map);
    }

    public Integer addPosition(Position position) {

        return positionDao.addPosition(position);
    }

    public Integer updatePosition(Position position) {

        return positionDao.updatePosition(position);
    }

    public Integer deletePosition(Integer id) {
        Integer flag = null;
        try {
            flag = positionDao.deletePosition(id);
        } catch (Exception e) {
            throw new RuntimeException();
        }

        return flag;
    }

}

PostServiceImpl.java

package com.shiyanlou.service.impl;

import java.util.List;
import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.shiyanlou.dao.PostDao;
import com.shiyanlou.domain.Post;
import com.shiyanlou.service.PostService;

@Transactional
@Service("postService")
public class PostServiceImpl implements PostService {

    @Autowired
    private PostDao postDao;

    public List findPosts(Map map) {

        return postDao.findPosts(map);
    }

    public Integer getCount(Map map) {

        return postDao.getCount(map);
    }

    public Integer addPost(Post post) {

        return postDao.addPost(post);
    }

    public Integer updatePost(Post post) {

        return postDao.updatePost(post);
    }

    public Integer deletePost(Integer id) {

        return postDao.deletePost(id);
    }

    public Post getPostById(Integer id) {

        return postDao.getPostById(id);
    }

}

AdminService.java

package com.shiyanlou.service;

import java.util.List;
import java.util.Map;

import com.shiyanlou.domain.Admin;

public interface AdminService {

    /** 登录
     *
     * @param admin
     * @return
     */
    public Admin login(Admin admin);

    /** 根据条件查询管理员
     *
     * @param map
     * @return
     */
    public List findAdmins(Map map);

    /** 根据条件查询管理员人数
     *
     * @param map
     * @return
     */
    public Integer getCount(Map map);

    /** 添加管理员
     *
     * @param admin
     * @return
     */
    public Integer addAdmin(Admin admin);

    /** 修改管理员
     *
     * @param admin
     * @return
     */
    public Integer updateAdmin(Admin admin);

    /** 删除管理员
     *
     * @param id
     * @return
     */
    public Integer deleteAdmin(Integer id);
}

DepartmentService.java

package com.shiyanlou.service;

import java.util.List;
import java.util.Map;

import com.shiyanlou.domain.Department;

public interface DepartmentService {

    /** 根据条件查询部门
     *
     * @param map
     * @return
     */
    public List findDepartments(Map map);

    /** 根据条件查询部门数量
     *
     * @param map
     * @return
     */
    public Integer getCount(Map map);

    /** 添加部门
     *
     * @param department
     * @return
     */
    public Integer addDepartment(Department department);

    /** 修改部门
     *
     * @param department
     * @return
     */
    public Integer updateDepartment(Department department);

    /** 删除部门
     *
     * @param id
     * @return
     */
    public Integer deleteDepartment(Integer id);
}

EmployeeService.java

package com.shiyanlou.service;

import java.util.List;
import java.util.Map;

import com.shiyanlou.domain.Employee;
import com.shiyanlou.domain.Post;

public interface EmployeeService {

    /** 根据条件查询员工
     *
     * @param map
     * @return
     */
    public ListfindEmployees(Map map);

    /** 根据条件查询员工人数
     *
     * @param map
     * @return
     */
    public Integer getCount(Map map);

    /** 添加员工
     *
     * @param employee
     * @return
     */
    public Integer addEmployee(Employee employee);

    /** 修改员工
     *
     * @param employee
     * @return
     */
    public Integer updateEmployee(Employee employee);

    /** 删除员工
     *
     * @param id
     * @return
     */
    public Integer deleteEmployee(String id);
}

PositionService.java

package com.shiyanlou.service;

import java.util.List;
import java.util.Map;

import com.shiyanlou.domain.Position;

public interface PositionService {

    /** 根据条件查询职位
     *
     * @param map
     * @return
     */
    public List findPositions(Map map);

    /** 根据条件查询职位数量
     *
     * @param map
     * @return
     */
    public Integer getCount(Map map);

    /** 添加职位
     *
     * @param position
     * @return
     */
    public Integer addPosition(Position position);

    /* 修改职位
     *
     * @param position
     * @return
     */
    public Integer updatePosition(Position position);

    /** 删除职位
     *
     * @param id
     * @return
     */
    public Integer deletePosition(Integer id);
}

PostService.java

package com.shiyanlou.service;

import java.util.List;
import java.util.Map;

import com.shiyanlou.domain.Post;

public interface PostService {

    /** 根据条件查询公告
     *
     * @param map
     * @return
     */
    public ListfindPosts(Map map);

    /** 根据条件查询公告数量
     *
     * @param map
     * @return
     */
    public Integer getCount(Map map);

    /** 添加公告
     *
     * @param post
     * @return
     */
    public Integer addPost(Post post);

    /** 修改公告
     *
     * @param post
     * @return
     */
    public Integer updatePost(Post post);

    /** 删除公告
     *
     * @param id
     * @return
     */
    public Integer deletePost(Integer id);

    /** 根据 ID 查询公告信息
     *
     * @param id
     * @return
     */
    public Post getPostById(Integer id);
}

util

DateUtil.java

package com.shiyanlou.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {
    public static Date getDate() throws ParseException{
        //获取当前系统时间
        Date date = new Date();
        //设置特定的事件格式
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        //将时间转为指定格式并返回
        return sdf.parse(sdf.format(date));
    }
}

IntegrateObject.java

package com.shiyanlou.util;

import com.shiyanlou.domain.Department;
import com.shiyanlou.domain.Employee;
import com.shiyanlou.domain.Position;

public class IntegrateObject {
    /**
     * 由于部门和职位在 Employee 中是对象关联映射,
     * 所以不能直接接收参数,需要创建 Department 对象和 Position 对象
     * */
    public static void genericAssociation(Integer dept_id,Integer pos_id,Employee employee){
        Department department = new Department();
        department.setId(dept_id);
        Position position = new Position();
        position.setId(pos_id);
        employee.setDepartment(department);
        employee.setPosition(position);
    }
}

JsonDateValueProcessor.java

package com.shiyanlou.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import net.sf.json.JsonConfig;
import net.sf.json.processors.JsonValueProcessor;

public class JsonDateValueProcessor implements JsonValueProcessor {

    private String format ="yyyy-MM-dd";

    public JsonDateValueProcessor() {
        super();
    }

    public JsonDateValueProcessor(String format) {
        super();
        this.format = format;
    }

    public Object processArrayValue(Object paramObject,
            JsonConfig paramJsonConfig) {
        return process(paramObject);
    }

    public Object processObjectValue(String paramString, Object paramObject,
            JsonConfig paramJsonConfig) {
        return process(paramObject);
    }

    private Object process(Object value){
        if(value instanceof Date){
            SimpleDateFormat sdf = new SimpleDateFormat(format,Locale.CHINA);
            return sdf.format(value);
        }
        return value == null ? "" : value.toString();
    }
}

ResponseUtil.java

package com.shiyanlou.util;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

public class ResponseUtil {
    public static void write(HttpServletResponse response, Object o)
            throws Exception {
        response.setContentType("text/html;charset=utf-8");
        response.addHeader("Access-Control-Allow-Origin", "*");
        PrintWriter out = response.getWriter();
        out.println(o.toString());
        out.flush();
        out.close();
    }
}

mappers

AdminMapper.xml

<?xml version="1.0" encoding="UTF-8"?>


    
    
        
        
        
        
    
    
    
    
    
    
    
    
    
        insert into admin_tb(username,password)
        values(#{username},#{password})
    
    
    
        update admin_tb set
        username=#{username},password=#{password} where admin_id=#{id}
    
    
    
        delete from admin_tb where
        admin_id=#{id}
    

DepartmentMapper.xml

<?xml version="1.0" encoding="UTF-8"?>


    
    
        
        
        
    
    
    
    
    
    
    
        insert into dept_tb(dept_name,dept_description)
        values(#{name},#{description})
    
    
    
        update dept_tb set
        dept_name=#{name},dept_description=#{description} where dept_id=#{id}
    
    
    
        delete from dept_tb where
        dept_id=#{id}
    

EmployeeMapper.xml

<?xml version="1.0" encoding="UTF-8"?>


    
    
        
        
        
        
        
        
        
        
        
        
            
            
        
        
            
            
        
    
    
    
    
    
    
    
        insert
        into employee_tb(emp_id,emp_name,sex,phone,email,address,education,birthday,dept_id,pos_id)
        values(#{id},#{name},#{sex},#{phone},#{email},#{address},#{education},#{birthday},#{department.id},#{position.id})
    
    
    
        update employee_tb set
        emp_name=#{name},sex=#{sex},phone=#{phone},email=#{email},address=#{address},education=#{education},birthday=#{birthday},dept_id=#{department.id},pos_id=#{position.id}
        where emp_id=#{id}
    
    
    
        delete from employee_tb
        where
        emp_id=#{id}
    

PositionMapper.xml

<?xml version="1.0" encoding="UTF-8"?>


    
    
        
        
        
    
    
    
    
    
    
    
        insert into position_tb(pos_name,pos_description)
        values(#{name},#{description})
    
    
    
        update position_tb set
        pos_name=#{name},pos_description=#{description} where pos_id=#{id}
    
    
    
        delete from position_tb where
        pos_id=#{id}
    

PostMapper.xml

<?xml version="1.0" encoding="UTF-8"?>


    
    
        
        
        
        
        
            
            
        
    
    
    
    
    
    
    
        insert
        into post_tb(title,content,admin_id,create_date)
        values(#{title},#{content},#{admin.id},#{date})
    
    
    
        update post_tb set
        title=#{title},content=#{content},admin_id=#{admin.id},create_date=#{date}
        where post_id=#{id}
    
    
    
        delete from post_tb
        where
        post_id=#{id}
    
    
    

webapp

home_page.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>




hrms_main


<script type="text/javascript"
    src="${pageContext.request.contextPath}/jquery-easyui-1.3.3/jquery.min.js"></script>
<script type="text/javascript"
    src="${pageContext.request.contextPath}/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
<script type="text/javascript">
    var url;
    function addTab(url, text, iconCls) {
        var content = "";
        $("#tabs").tabs("add", {
            title : text,
            iconCls : iconCls,
            closable : true,
            content : content
        });
    }
    function openTab(text, url, iconCls) {
        if ($("#tabs").tabs("exists", text)) {
            $("#tabs").tabs("close", text);
            addTab(url, text, iconCls);
            $("#tabs").tabs("select", text);
        } else {
            addTab(url, text, iconCls);
        }
    }
    /* 退出 */
    function logout() {
        $.messager
                .confirm(
                        "system prompt",
                        "Do you want to exit?",
                        function(r) {
                            if (r) {
                                window.location.href = "${pageContext.request.contextPath}/admin/logout";
                            }
                        });
    }
</script>

    
  Current Admin\uff1a ${sessionScope.currentAdmin.username}
Human Affairs Management System
www.shiyanlou.com

index.jsp



Hello World!

login.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>




hrms-login
<script type="text/javascript"
    src="${pageContext.request.contextPath}/js/jquery.min.js"></script>

<script type="text/javascript">
    /* 登录 */
    function login() {
        var username = $("#username").val();
        var password = $("#password").val();
        if (username == null || username == "") {
            alert("username can't be empty\uff01");
            return;
        }
        if (password == null || password == "") {
            alert("password can't be empty\uff01");
            return;
        }
        $("#adminlogin").submit();

    }
    /* 用户名或密码错误时显示 */
    if ('${errorMsg}' != '') {
        alert('${errorMsg}');
    }
    /* 拦截器显示信息 */
    if ('${message}' != '') {
        alert('${message}');
    }
</script>


    
 
 

postContent.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>




Post Content

${requestScope.postContent}

pom.xml


    4.0.0

    com.shiyanlou
    hrms
    0.0.1-SNAPSHOT
    war

    hrms
    http://maven.apache.org

    

        5.1.25
        3.3.0
        1.2.2
        5.1.1.RELEASE
        UTF-8
        1.2
        true
    

    
        
            junit
            junit
            4.12
            test
        
        
            org.springframework
            spring-test
            ${spring.version}
            test
        

        
        
            commons-logging
            commons-logging
            1.1.3
        
        
            commons-collections
            commons-collections
            3.2.1
        
        
            commons-io
            commons-io
            2.4
        
        
            commons-lang
            commons-lang
            2.6
        
        
        
            org.mybatis
            mybatis
            ${mybatis.version}
        
        
            org.mybatis
            mybatis-spring
            ${mybatis-spring.version}
        
        
            mysql
            mysql-connector-java
            ${jdbc.driver.version}
            runtime
        
        
        
            org.slf4j
            slf4j-api
            1.7.7
        
        
            org.slf4j
            slf4j-log4j12
            1.7.7
        
        
            log4j
            log4j
            1.2.16
        

        
        
            org.aspectj
            aspectjrt
            1.7.4
        
        
            org.aspectj
            aspectjweaver
            1.7.4
        

                
        
            org.springframework
            spring-core
            ${spring.version}
        
        
            org.springframework
            spring-beans
            ${spring.version}
        
        
            org.springframework
            spring-context-support
            ${spring.version}
        
        
            org.springframework
            spring-jdbc
            ${spring.version}
        
        
            org.springframework
            spring-tx
            ${spring.version}
        
        
            org.springframework
            spring-webmvc
            ${spring.version}
        

        
            javax.servlet
            javax.servlet-api
            3.1.0
            provided
        
        
            javax.servlet.jsp
            jsp-api
            2.2
        
        
            javax.servlet
            jstl
            1.2
        

        
            net.sf.json-lib
            json-lib
            2.2.3
            jdk15
        
        
            com.fasterxml.jackson.core
            jackson-databind
            2.9.7
        

        
            com.alibaba
            fastjson
            1.2.4
        

        
            commons-fileupload
            commons-fileupload
            1.3.1
        
        
            org.apache.geronimo.specs
            geronimo-servlet_2.4_spec
            1.1.1
            provided
        

        
            commons-codec
            commons-codec
            1.9
        
        
            org.json
            json
            20160810
        
        
        
            com.baidu
            ueditor
            1.1.2
        
        
            com.alibaba
            druid
            1.0.24
        
    
  
    
      
      
        org.eclipse.jetty
        jetty-maven-plugin
        9.4.12.v20180830
        
            10
            
                /
            
        
      
    
  

项目测试

拦截器测试

启动服务后,点击工具--web服务按钮,直接访问主页,无法进入主页,弹出窗口提示 Please login in first,并回到登录页面,说明拦截器起作用。

登录测试

在登录页面不输入或者输入错误的用户名或密码,如这里我只输入了用户名 superadmin,密码未输入,点击登录,弹出窗口提示 Please check your username or password!

输入正确的用户名和密码,如用户名:superadmin,密码:123456,点击登录,登录成功进入系统主页。

退出测试

点击主页左侧 System Manage 下的 Exit 链接,即可退出到登录页面。

系统管理(管理员管理)测试

(1)查询管理员

点击主页左侧 System Manage 下的 Admin List 链接,显示所有管理员的信息。

Username 旁的文本框中输入用户名(可以是不完整的,如 super),点击 Search

(2)添加管理员

点击 Add 链接,弹出 Add new admin 窗口。

输入合格的用户名和密码(均不能为空)后点击 Save,保存成功。

(3)修改管理员

不勾选任何管理员,直接点击 Modify 链接,弹出 Please choose a data to edit! 对话框。

选择 superadmin,点击 Modify 链接,弹出 Can't modify superadmin' information 对话框。

选择一个管理员,如刚添加的 admin4,点击 Modify 链接,弹出 Edit admin information 窗口。

将用户名 admin4 修改为 admin5,点击 Save,保存成功。

(4)删除管理员

不勾选任何管理员,直接点击 Delete 链接,弹出 Please choose the data to delete! 对话框。

选中一条或多条数据点击 Delete 链接,提示是否删除,点击 OK

如果这条数据是 superadmin,或当前登录的管理员,弹出 Can't delete superAdmin or current admin! 对话框。

如果是其他数据则删除成功。

公告管理测试

(1)查询公告

点击主页左侧 Post Manage 下的 Post Info 链接,显示所有公告的信息。

Title 旁的文本框中输入公告标题(可以是不完整的,如 notice),点击 Search

选择一个公告,点击 Show Content 链接,跳转至新页面,显示公告的内容详情,如在这里选择 Leave notice

(2)添加公告

点击 Add 链接,弹出 Add post 窗口。

Title Content 均不能为空,输入内容后,点击 Save,保存成功。

(3)修改公告

选择一条公告,如刚添加的 shiyanloupost,点击 Modify 链接,弹出 Edit post 窗口。

将公告标题 shiyanloupost 修改为 newshiyanloupost,点击 Save,保存成功。

(4)删除公告

选中一条或多条数据点击 Delete 链接,提示是否删除,点击 OK,删除成功。

部门管理测试

(1)查询部门

点击主页左侧 Department Manage 下的 Department Info 链接,显示所有部门的信息。

Name 旁的文本框中输入部门名称(可以是不完整的,如 deve),点击 Search

(2)添加部门

点击 Add 链接,弹出 Add new department 窗口。

部门名称 Name 和描述 Description 均不能为空,输入内容后,点击 Save,保存成功。

(3)修改部门

选择一个部门,如刚添加的 human resources,点击 Modify 链接,弹出 Edit department information 窗口。

将部门描述修改为 human resources,shiyanlou!,点击 Save,保存成功。

(4)删除部门

选中一条或多条数据点击 Delete 链接,提示是否删除,点击 OK

如果该部门有员工,删除失败。

否则,删除成功。

职位管理测试

(1)查询职位

点击主页左侧 Position Manage 下的 Position Info 链接,显示所有职位的信息。

Name 旁的文本框中输入职位名称(可以是不完整的,如 Java),点击 Search

(2)添加职位

点击 Add 链接,弹出 Add new position 窗口。

职位名称 Name 和描述 Description 均不能为空,输入内容后,点击 Save,保存成功。

(3)修改职位

选择一个职位,如刚添加的 python engineers,点击 Modify 链接,弹出 Edit position information 窗口。

将职位描述修改为 python engineers for shiyanlou!,点击 Save,保存成功。

(4)删除职位

选中一条或多条数据点击 Delete 链接,提示是否删除,点击 OK

如果该职位有员工,删除失败。

否则,删除成功。

员工管理测试

(1)查询员工

点击主页左侧 Employee Manage 下的 Employee Info 链接,显示所有员工的信息。

根据 id 查询员工,如输入 001,点击 Search

根据 id 和 部门查询员工,如分别输入 001 course,点击 Search

其他条件查询类似,这里不再演示。

(2)添加员工

点击 Add 链接,弹出 Add new employee 窗口。

填写信息提交,会进行包括如下校验:

空校验:

id 必须为数字:

正确的手机号格式:

重复 id 校验:

输入合格的信息后,点击 Save,保存成功。

(3)修改员工

选择一个员工,如刚添加的 id 为 10003 的员工,点击 Modify 链接,弹出 Edit employee information 窗口。

将该员工的地址修改为 chongqing,点击 Save,保存成功。

4)删除员工

选中一条或多条数据点击 Delete 链接,提示是否删除,点击 OK,删除成功。

相关