基于javaweb+mysql的ssm+maven员工考勤请假管理系统(java+ssm+jsp+bootstrap+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SSM+Maven员工考勤请假管理系统(java+ssm+jsp+bootstrap+mysql)
项目介绍
本项目包含管理员、部门经理、员工三种角色;
部门经理角色包含以下功能: 个人信息管理,请假信息审批,部门考勤记录,考勤系统管理等功能。
管理员角色包含以下功能: 管理员登录,员工管理,请假统计等功能。
员工角色包含以下功能: 员工登录,员工签到,考勤记录,请假,请假记录查询等功能。
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 5.数据库:MySql 5.7版本; 6.是否Maven项目:是;
技术栈
- 后端:Spring+SpringMVC+Mybatis 2. 前端:JSP+CSS+JavaScript+jquery+bootstrap
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中mysql.properties配置文件中的数据库配置改为自己的配置; 4. 运行项目,输入localhost:8080/ 登录
//修改密码
@RequestMapping(value = "/passwordReset")
public String passwordRest() throws Exception {
return "/staff/passwordReset";
}
}
package com.system.controller;
@Controller
@RequestMapping("/admin")
public class AdminController {
@Resource(name = "staffCustomServiceImpl")
private StaffCustomService staffCustomService;
@Resource(name = "departmentServiceImpl")
private DepartmentService departmentService;
@Resource(name = "loginServiceImpl")
private LoginService loginService;
@Controller
@RequestMapping(value = "/managers")
public class ManagerController {
@Resource(name = "staffServiceImpl")
private StaffService staffService;
@Resource(name = "departmentServiceImpl")
private DepartmentService departmentService;
@Resource(name = "signServiceImpl")
private SignService signService;
@Resource(name = "leaveServiceImpl")
private LeaveService leaveService;
//显示个人信息
@RequestMapping(value="/showMassage", method = {RequestMethod.GET})
public String staffMassageShow(Model model) throws Exception {
//获取当前用户id
Subject subject = SecurityUtils.getSubject();
String id = (String) subject.getPrincipal();
//通过id获取员工信息
Staff staff = staffService.findById(id);
if (staff == null) {
throw new CustomException("未找到员工信息");
}
List<Department> list = departmentService.finAll();
model.addAttribute("departmentList", list);
model.addAttribute("staff", staff);
return "/managers/showMassage";
}
//更新个人信息
@RequestMapping(value="/showMassage", method = {RequestMethod.POST})
public String staffMassageUpdate(String tel,String email,String hobby) throws Exception {
//获取当前用户id
Subject subject = SecurityUtils.getSubject();
json.put("handleTime", "--");
jarray.set(i,json);
}
}
Map<String, Object> map = new HashMap<String, Object>();
if(returnLeaves != null) {
map.put("total", jarray.size());
map.put("rows", jarray);
}
/*String resultJson = JSON.toJSONString(leaveList);
System.out.println(resultJson);*/
return map;
}
// 本账户密码重置
@RequestMapping("/passwordReset")
public String passwordRestUI() throws Exception {
return "/admin/passwordReset";
}
}
package com.system.controller;
* 只要实现该接口,并配置到spring 容器里,该类就能
* 成为默认全局异常处理类
*
* 全局异常处理器只有一个,配置多个也没用。
*/
public class CustomExceptionResolver implements HandlerExceptionResolver {
public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
ModelAndView modelAndView = new ModelAndView();
CustomException customException;
if (e instanceof CustomException) {
customException = (CustomException)e;
} else if (e instanceof UnknownAccountException) {
//用户名错误异常
modelAndView.addObject("message", "没有该用户");
modelAndView.setViewName("/error");
return modelAndView;
} else if (e instanceof IncorrectCredentialsException) {
//用户名错误异常
modelAndView.addObject("message", "密码错误");
modelAndView.setViewName("/error");
return modelAndView;
}
else {
customException = new CustomException(e.getMessage());
}
//错误信息
String message = customException.getMessage();
//错误信息传递和错误页面跳转
modelAndView.addObject("message", message);
modelAndView.setViewName("/error");
return modelAndView;
}
}
package com.system.controller;
@Controller
@RequestMapping("/admin")
public class AdminController {
@Resource(name = "staffCustomServiceImpl")
private StaffCustomService staffCustomService;
@Resource(name = "departmentServiceImpl")
private DepartmentService departmentService;
@Resource(name = "loginServiceImpl")
private LoginService loginService;
@Resource(name = "adminServiceImpl")
private AdminService adminService;
// 员工信息显示
@RequestMapping("/showStaff")
public String showStudent(Model model, Integer page) throws Exception {
List<StaffCustom> list = null;
//页码对象
PagingVO pagingVO = new PagingVO();
//设置总页数
pagingVO.setTotalCount(staffCustomService.getStaffCount());
if (page == null || page == 0) {
pagingVO.setToPageNo(1);
@Controller
@RequestMapping("/admin")
public class AdminController {
@Resource(name = "staffCustomServiceImpl")
private StaffCustomService staffCustomService;
@Resource(name = "departmentServiceImpl")
private DepartmentService departmentService;
@Resource(name = "loginServiceImpl")
private LoginService loginService;
model.addAttribute("staffList", list);
model.addAttribute("pagingVO", pagingVO);
return "/admin/showStaff";
}
//显示员工详细信息
@RequestMapping("/showStaffDetail")
public String showStaffDetail(String staffId, Model model) throws Exception{
StaffCustom staffDetail = staffCustomService.findById(staffId);
model.addAttribute("staffDetail", staffDetail);
List<Department> list = departmentService.finAll();
model.addAttribute("departmentList", list);
return "/admin/showStaffDetail";
}
// 添加员工信息页面显示
@RequestMapping(value = "/addStaff", method = {RequestMethod.GET})
public String addStudentUI(Model model) throws Exception {
List<Department> list = departmentService.finAll();
model.addAttribute("departmentList", list);
return "/admin/addStaff";
}
// 添加员工信息操作
@RequestMapping(value = "/addStaff", method = {RequestMethod.POST})
public String addStudent(StaffCustom staffCustom, Model model) throws Exception {
/*System.out.println(staffCustom.getRole());*/
Boolean result = staffCustomService.save(staffCustom);
if (!result) {
model.addAttribute("message", "员工编号重复");
return "/error";
}
//添加成功后,也添加到登录表
//重定向
return "redirect:/admin/showStaff";
}
// 修改员工信息处理
@RequestMapping(value = "/editStaff", method = {RequestMethod.POST})
@ResponseBody
public boolean editStaff(int role,int department,String staffId) throws Exception {
Map<String,Object> paramMap = new HashMap<String, Object>();
paramMap.put("staffId",staffId);
paramMap.put("department",department);
/*String resultJson = JSON.toJSONString(leaveList);
System.out.println(resultJson);*/
return map;
}
// 本账户密码重置
@RequestMapping("/passwordReset")
public String passwordRestUI() throws Exception {
return "/admin/passwordReset";
}
}
package com.system.controller;
@Controller
@RequestMapping(value = "/managers")
public class ManagerController {
@Resource(name = "staffServiceImpl")
private StaffService staffService;
return "/managers/leaveRecord";
}
// 显示请假申请详细信息
@RequestMapping(value = "/leaveDetail")
public String gradeCourse(Integer recordId, Model model) throws Exception {
if (recordId == null) {
return "";
}
Leave leaveDetail= leaveService.findByRecordId(recordId);
model.addAttribute("leaveDetail", leaveDetail);
return "/managers/showLeaveDetail";
}
//更新请假单审核信息
@RequestMapping(value="/handleLeave")
@ResponseBody
public boolean handleLeave(String reply,String result,Integer recordId) throws Exception {
Map<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("recordId",recordId);
paramMap.put("reply",reply);
paramMap.put("result",result);
leaveService.handleLeave(paramMap);
return true;
}
}
package com.system.exception;
/**
* 全局异常处理器
* springmvc提供一个HandlerExceptionResolver接口
* 只要实现该接口,并配置到spring 容器里,该类就能
* 成为默认全局异常处理类
*
* 全局异常处理器只有一个,配置多个也没用。
*/
public class CustomExceptionResolver implements HandlerExceptionResolver {
public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
ModelAndView modelAndView = new ModelAndView();
* springmvc提供一个HandlerExceptionResolver接口
* 只要实现该接口,并配置到spring 容器里,该类就能
* 成为默认全局异常处理类
*
* 全局异常处理器只有一个,配置多个也没用。
*/
public class CustomExceptionResolver implements HandlerExceptionResolver {
public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
ModelAndView modelAndView = new ModelAndView();
CustomException customException;
if (e instanceof CustomException) {
customException = (CustomException)e;
} else if (e instanceof UnknownAccountException) {
//用户名错误异常
modelAndView.addObject("message", "没有该用户");
modelAndView.setViewName("/error");
return modelAndView;
} else if (e instanceof IncorrectCredentialsException) {
//用户名错误异常
modelAndView.addObject("message", "密码错误");
modelAndView.setViewName("/error");
return modelAndView;
}
else {
customException = new CustomException(e.getMessage());
}
//错误信息
String message = customException.getMessage();
//错误信息传递和错误页面跳转
modelAndView.addObject("message", message);
modelAndView.setViewName("/error");
return modelAndView;
}
}
package com.system.controller;
//错误信息传递和错误页面跳转
modelAndView.addObject("message", message);
modelAndView.setViewName("/error");
return modelAndView;
}
}
package com.system.controller;
/**
*/
@Controller
public class LoginController {
//登录跳转
@RequestMapping(value = "/login", method = {RequestMethod.GET})
public String loginUI() throws Exception {
return "/login";
}
@RequestMapping(value="/logout",method = {RequestMethod.GET})
public String logout() throws Exception{
return "/login";
}
//登录表单处理
@RequestMapping(value = "/login", method = {RequestMethod.POST})
public String login(Model model,Staff staff) throws Exception {
Sign signOut= new Sign();
signOut.setStaffId(id);
signOut.setDepartmentId(staff.getDepartmentId());
signOut.setSignOutTime(sign_out_time);
//判断当天是否已经签到
int isSignIn = signService.isSignIn(signOut);
if(isSignIn == 0){
response.getWriter().println("今日还未签到,请先签到");
}else {
//判断签到时间状态,18:00之后0-正常,之前1-迟到
Date endTime = dateFormat.parse("18:00:00");
Calendar date = Calendar.getInstance();
date.setTime(dateFormat.parse(time));
Calendar end = Calendar.getInstance();
end.setTime(endTime);
if (date.before(end)) {
signOut.setSignOutState("1");
} else signOut.setSignOutState("0");
//更新签退记录到已有签到记录
signService.signOut(signOut);
//返回时间到前端页面
response.getWriter().println("签退成功\n"+"签退时间:"+time);
}
}
//显示个人信息
@RequestMapping(value="/showMassage", method = {RequestMethod.GET})
public String staffMassageShow(Model model) throws Exception {
//获取当前用户id
Subject subject = SecurityUtils.getSubject();
String id = (String) subject.getPrincipal();
//通过id获取员工信息
Staff staff = staffService.findById(id);
if (staff == null) {
throw new CustomException("未找到员工信息");
}
List<Department> list = departmentService.finAll();
model.addAttribute("departmentList", list);
model.addAttribute("staff", staff);
return "/staff/showMassage";
}
//更新个人信息
@RequestMapping(value = "/showMassage", method = {RequestMethod.POST})
public String staffMassageUpdate(HttpServletRequest request) throws Exception {
//获取当前用户id
Subject subject = SecurityUtils.getSubject();
String id = (String) subject.getPrincipal();
String staffId = request.getParameter("staffId");
String staffName = request.getParameter("staffName");
String sex = request.getParameter("sex");
//更新请假单审核信息
@RequestMapping(value="/handleLeave")
@ResponseBody
public boolean handleLeave(String reply,String result,Integer recordId) throws Exception {
Map<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("recordId",recordId);
paramMap.put("reply",reply);
paramMap.put("result",result);
leaveService.handleLeave(paramMap);
return true;
}
}
package com.system.exception;
/**
* 全局异常处理器
* springmvc提供一个HandlerExceptionResolver接口
* 只要实现该接口,并配置到spring 容器里,该类就能
* 成为默认全局异常处理类
*
* 全局异常处理器只有一个,配置多个也没用。
*/
public class CustomExceptionResolver implements HandlerExceptionResolver {
public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
ModelAndView modelAndView = new ModelAndView();
CustomException customException;
if (e instanceof CustomException) {
customException = (CustomException)e;
} else if (e instanceof UnknownAccountException) {
//用户名错误异常
modelAndView.addObject("message", "没有该用户");
modelAndView.setViewName("/error");
return modelAndView;
} else if (e instanceof IncorrectCredentialsException) {
//用户名错误异常
modelAndView.addObject("message", "密码错误");
modelAndView.setViewName("/error");
return modelAndView;
public String showSign() throws Exception {
return "/admin/showSign";
}
// 考勤记录统计查询
@RequestMapping(value = "/loadReportInfoData")
public String loadReportInfoData(Model model,ReportInfo reportInfo) throws Exception {
List<ReportInfo> reportInfoList = new ArrayList<ReportInfo>();
try {
reportInfoList = adminService.loadReportInfoData(reportInfo);
} catch (Exception e) {
e.printStackTrace();
}
model.addAttribute("reportInfoList", reportInfoList);
return "/admin/showSign";
}
//考勤记录详细信息显示
@RequestMapping(value = "/loadReportDetailData")
public void loadReportDetailData(PrintWriter printWriter,String reportId, Model model) throws Exception {
List<ReportDetail> reportDetailList = new ArrayList<ReportDetail>();
try {
reportDetailList = adminService.loadReportDetailData(reportId);
} catch (Exception e) {
e.printStackTrace();
}
/*model.addAttribute("reportDetailList", reportDetailList);*/
/*System.out.println(reportDetailList.size());*/
String resultJson = JSON.toJSONString(reportDetailList);
printWriter.write(resultJson);
printWriter.flush();
printWriter.close();
}
// 请假记录查询页面显示
@RequestMapping(value = "/showLeave")
public String showLeave() throws Exception {
return "/admin/showLeave";
}
// 请假记录查询页面显示
@RequestMapping(value = "/showLeaveRecord")
@ResponseBody
public Map<String, Object> showLeaveRecord(String searchText) throws Exception {
searchText = searchText == null?"":searchText;
List<Leave> leaveList = new ArrayList<Leave>();
List<Leave> returnLeaves = new ArrayList<Leave>();
try {
leaveList = adminService.loadLeaveList();
} catch (Exception e) {
e.printStackTrace();
Staff staff = staffService.findById(id);
if (staff == null) {
throw new CustomException("未找到员工信息");
}
List<Department> list = departmentService.finAll();
model.addAttribute("departmentList", list);
model.addAttribute("staff", staff);
return "/staff/showMassage";
}
//更新个人信息
@RequestMapping(value = "/showMassage", method = {RequestMethod.POST})
public String staffMassageUpdate(HttpServletRequest request) throws Exception {
//获取当前用户id
Subject subject = SecurityUtils.getSubject();
String id = (String) subject.getPrincipal();
String staffId = request.getParameter("staffId");
String staffName = request.getParameter("staffName");
String sex = request.getParameter("sex");
Integer departmentId = null;
Integer role = null;
Date grade = null;
Date birthday = null;
String tel = request.getParameter("tel");
String email = request.getParameter("email");
String hobby = request.getParameter("hobby");
String password = request.getParameter("password");
// 正则表达式,用于验证整数和日期
String intRegex = "^-?[1-9]\\d*$";
String dateRegex = "^\\d{4}-\\d{2}-\\d{2}$";
Pattern intPattern = Pattern.compile(intRegex);
Pattern datePattern = Pattern.compile(dateRegex);
// 判断departmentId是否为整数
String departmentIdStr = request.getParameter("departmentId");
if (departmentIdStr != null && !departmentIdStr.isEmpty() && intPattern.matcher(departmentIdStr).matches()) {
departmentId = Integer.parseInt(departmentIdStr);
}
// 判断role是否为整数
String roleStr = request.getParameter("role");
if (roleStr != null && !roleStr.isEmpty() && intPattern.matcher(roleStr).matches()) {
role = Integer.parseInt(roleStr);
}
// 判断grade是否为日期
String gradeStr = request.getParameter("grade");
if (gradeStr != null && !gradeStr.isEmpty() && datePattern.matcher(gradeStr).matches()) {
//显示个人信息
@RequestMapping(value="/showMassage", method = {RequestMethod.GET})
public String staffMassageShow(Model model) throws Exception {
//获取当前用户id
Subject subject = SecurityUtils.getSubject();
String id = (String) subject.getPrincipal();
//通过id获取员工信息
Staff staff = staffService.findById(id);
if (staff == null) {
throw new CustomException("未找到员工信息");
}
List<Department> list = departmentService.finAll();
model.addAttribute("departmentList", list);
model.addAttribute("staff", staff);
return "/staff/showMassage";
}
//更新个人信息
@RequestMapping(value = "/showMassage", method = {RequestMethod.POST})
public String staffMassageUpdate(HttpServletRequest request) throws Exception {
//获取当前用户id
Subject subject = SecurityUtils.getSubject();
String id = (String) subject.getPrincipal();
String staffId = request.getParameter("staffId");
String staffName = request.getParameter("staffName");
String sex = request.getParameter("sex");
Integer departmentId = null;
Integer role = null;
Date grade = null;
Date birthday = null;
String tel = request.getParameter("tel");
String email = request.getParameter("email");
String hobby = request.getParameter("hobby");
String password = request.getParameter("password");
// 正则表达式,用于验证整数和日期
String intRegex = "^-?[1-9]\\d*$";
String dateRegex = "^\\d{4}-\\d{2}-\\d{2}$";
Pattern intPattern = Pattern.compile(intRegex);
Pattern datePattern = Pattern.compile(dateRegex);
// 判断departmentId是否为整数
String departmentIdStr = request.getParameter("departmentId");
// 添加员工信息页面显示
@RequestMapping(value = "/addStaff", method = {RequestMethod.GET})
public String addStudentUI(Model model) throws Exception {
List<Department> list = departmentService.finAll();
model.addAttribute("departmentList", list);
return "/admin/addStaff";
}
// 添加员工信息操作
@RequestMapping(value = "/addStaff", method = {RequestMethod.POST})
public String addStudent(StaffCustom staffCustom, Model model) throws Exception {
/*System.out.println(staffCustom.getRole());*/
Boolean result = staffCustomService.save(staffCustom);
if (!result) {
model.addAttribute("message", "员工编号重复");
return "/error";
}
//添加成功后,也添加到登录表
//重定向
return "redirect:/admin/showStaff";
}
// 修改员工信息处理
@RequestMapping(value = "/editStaff", method = {RequestMethod.POST})
@ResponseBody
public boolean editStaff(int role,int department,String staffId) throws Exception {
Map<String,Object> paramMap = new HashMap<String, Object>();
paramMap.put("staffId",staffId);
paramMap.put("department",department);
paramMap.put("role",role);
staffCustomService.editStaff(paramMap);
return true;