基于javaweb+mysql的ssm+maven员工薪资工资管理系统(JavaWeb JSP MySQL Servlet SSM SpringBoot Bootstrap Ajax)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
技术框架
JavaBean MVC JSP SSM(Spring SpringMVC MyBatis) Maven MySQL CSS JavaScript Bootstrap Ajax
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
登录、注册、退出、用户模块、公告模块、部门模块、员工模块、工资模块的增删改查管理
eclipse/MyEclipse运行:
idea运行:
public void delete(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");
deptService.delete(Arrays.asList(id));
this.redirectList(request, response);
}
/**
* 编辑部门
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("deptEdit")
public void edit(Dept vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
deptService.update(vo);
this.redirectList(request, response);
}
/**
* 获取部门的详细信息(详情页面与编辑页面要显示该部门的详情)并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping({"deptGet", "deptEditPre"})
public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");//取出主键id
Dept vo = deptService.get(id);
response.getWriter().println(com.alibaba.fastjson.JSONObject.toJSONString(vo));
}
/**
* 根据条件查询部门的列表并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("deptList")
public void list(HttpServletResponse response, HttpServletRequest request) throws IOException {
this.redirectList(request, response);
}
/**
* 跳转到列表页面
*
* @param request
request.getSession().setAttribute("pageBean", pb);
request.getSession().setAttribute("list", pb.getList());
response.sendRedirect("salary_list.jsp");
}
}
@Controller
@RequestMapping
public class DeptController {
@Autowired
private DeptService deptService;
/**
* 增加部门
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("deptAdd")
public void add(Dept vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
//调用Service层的增加(insert)方法
deptService.insert(vo);
this.redirectList(request, response);
}
/**
* 删除部门
*
* @param response
* @param request
* @throws IOException
*/
* 获取部门的详细信息(详情页面与编辑页面要显示该部门的详情)并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping({"deptGet", "deptEditPre"})
public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");//取出主键id
Dept vo = deptService.get(id);
response.getWriter().println(com.alibaba.fastjson.JSONObject.toJSONString(vo));
}
/**
* 根据条件查询部门的列表并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("deptList")
public void list(HttpServletResponse response, HttpServletRequest request) throws IOException {
this.redirectList(request, response);
}
/**
* 跳转到列表页面
*
* @param request
* @param response
*/
private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {
//查询列和关键字
String searchColumn = request.getParameter("searchColumn");
String keyword = request.getParameter("keyword");
Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
params.put("searchColumn", searchColumn);//要查询的列
params.put("keyword", keyword);//查询的关键字
Map<String, Object> map = deptService.list(params);
request.getSession().setAttribute("list", map.get("list"));
Integer totalRecord = (Integer) map.get("totalCount");//根据查询条件取出对应的总记录数,用于分页
String pageNum = request.getParameter("pageNum");//封装分页参数
com.demo.util.PageBean<Object> pb = new com.demo.util.PageBean(Integer.valueOf(pageNum != null ? pageNum : "1"), totalRecord);
params.put("startIndex", pb.getStartIndex());
params.put("pageSize", pb.getPageSize());
List list = (List) deptService.list(params).get("list");//根据分页参数startIndex、pageSize查询出来的最终结果list
pb.setServlet("deptList");
pb.setSearchColumn(searchColumn);
Map<String, Object> map = salaryService.list(params);
request.getSession().setAttribute("list", map.get("list"));
Integer totalRecord = (Integer) map.get("totalCount");//根据查询条件取出对应的总记录数,用于分页
String pageNum = request.getParameter("pageNum");//封装分页参数
com.demo.util.PageBean<Object> pb = new com.demo.util.PageBean(Integer.valueOf(pageNum != null ? pageNum : "1"), totalRecord);
params.put("startIndex", pb.getStartIndex());
params.put("pageSize", pb.getPageSize());
List list = (List) salaryService.list(params).get("list");//根据分页参数startIndex、pageSize查询出来的最终结果list
pb.setServlet("salaryList");
pb.setSearchColumn(searchColumn);
pb.setKeyword(keyword);
pb.setList(list);
request.getSession().setAttribute("pageBean", pb);
request.getSession().setAttribute("list", pb.getList());
response.sendRedirect("salary_list.jsp");
}
}
@Controller
@RequestMapping
public class DeptController {
@Autowired
private DeptService deptService;
/**
* 增加部门
@Controller
@RequestMapping
public class DeptController {
@Autowired
private DeptService deptService;
/**
* 增加部门
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("deptAdd")
public void add(Dept vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
//调用Service层的增加(insert)方法
deptService.insert(vo);
this.redirectList(request, response);
}
/**
* 删除部门
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("deptDelete")
public void delete(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");
deptService.delete(Arrays.asList(id));
this.redirectList(request, response);
}
/**
* 编辑部门
*
* @param response
* @param request
* @throws IOException
*/
}
}
@Controller
@RequestMapping
public class SalaryController {
@Autowired
private SalaryService salaryService;
/**
* 增加工资
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("salaryAdd")
public void add(Salary vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
//调用Service层的增加(insert)方法
salaryService.insert(vo);
this.redirectList(request, response);
}
@Controller
public class AuthController extends HttpServlet {
@Autowired
private UserService userService;
@RequestMapping("authLogin")
public void login(HttpServletResponse response, HttpServletRequest request) throws IOException, ServletException {
String username = request.getParameter("username");
String password = request.getParameter("password");
String validationCode = request.getParameter("validationCode");
if (validationCode != null && !validationCode.equals(request.getSession().getAttribute("validationCode"))) {//验证码不通过
request.getSession().setAttribute("alert_msg", "错误:验证码不正确!");
request.getRequestDispatcher("login.jsp").forward(request, response);
return;
}
Map<String, Object> params = new HashMap();
List<User> list = (List<User>) userService.list(params).get("list");
for (User user : list) {
if (user.getUsername().equals(username) && user.getPassword().equals(password)) {//找到这个管理员了
request.getSession().setAttribute("loginUser", user);
request.getSession().setMaxInactiveInterval(Integer.MAX_VALUE);
request.getRequestDispatcher("userList").forward(request, response);
return;
}
}
request.getSession().setAttribute("alert_msg", "错误:用户名或密码错误!");
request.getRequestDispatcher("login.jsp").forward(request, response);
}
@RequestMapping("authRegister")
public void register(HttpServletResponse response, HttpServletRequest request) throws IOException, ServletException {
String username = request.getParameter("username");
String password = request.getParameter("password");
System.out.println("username=" + username);
System.out.println("password=" + password);
// 返回一个随机颜色(Color对象)
private Color getRandomColor(int minColor, int maxColor) {
Random random = new Random();
// 保存minColor最大不会超过255
if (minColor > 255)
minColor = 255;
// 保存minColor最大不会超过255
if (maxColor > 255)
maxColor = 255;
// 获得红色的随机颜色值
int red = minColor + random.nextInt(maxColor - minColor);
// 获得绿色的随机颜色值
int green = minColor + random.nextInt(maxColor - minColor);
// 获得蓝色的随机颜色值
int blue = minColor + random.nextInt(maxColor - minColor);
return new Color(red, green, blue);
}
}
@Controller
@RequestMapping
public class EmployeeController {
@Autowired
private EmployeeService employeeService;
String searchColumn = request.getParameter("searchColumn");
String keyword = request.getParameter("keyword");
Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
params.put("searchColumn", searchColumn);//要查询的列
params.put("keyword", keyword);//查询的关键字
Map<String, Object> map = userService.list(params);
request.getSession().setAttribute("list", map.get("list"));
Integer totalRecord = (Integer) map.get("totalCount");//根据查询条件取出对应的总记录数,用于分页
String pageNum = request.getParameter("pageNum");//封装分页参数
com.demo.util.PageBean<Object> pb = new com.demo.util.PageBean(Integer.valueOf(pageNum != null ? pageNum : "1"), totalRecord);
params.put("startIndex", pb.getStartIndex());
params.put("pageSize", pb.getPageSize());
List list = (List) userService.list(params).get("list");//根据分页参数startIndex、pageSize查询出来的最终结果list
pb.setServlet("userList");
pb.setSearchColumn(searchColumn);
pb.setKeyword(keyword);
pb.setList(list);
request.getSession().setAttribute("pageBean", pb);
request.getSession().setAttribute("list", pb.getList());
response.sendRedirect("user_list.jsp");
}
}
/**
* 拦截器
*/
public class LoginInterceptor implements HandlerInterceptor {
//@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o) throws Exception {
HttpSession session = request.getSession();
//移除错误提示
session.removeAttribute("alert_msg");
//登录拦截
String uri = request.getRequestURI().substring(request.getRequestURI().lastIndexOf("/"));
String[] access = new String[]{"login", "logout", "register", ".css", ".js", ".png", ".jpg", "validationCode"};
for (String action : access) {
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping({"userGet", "userEditPre"})
public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");//取出主键id
User vo = userService.get(id);
response.getWriter().println(com.alibaba.fastjson.JSONObject.toJSONString(vo));
}
/**
* 根据条件查询用户的列表并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("userList")
public void list(HttpServletResponse response, HttpServletRequest request) throws IOException {
this.redirectList(request, response);
}
/**
* 跳转到列表页面
*
* @param request
* @param response
*/
private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {
//查询列和关键字
String searchColumn = request.getParameter("searchColumn");
String keyword = request.getParameter("keyword");
Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
params.put("searchColumn", searchColumn);//要查询的列
params.put("keyword", keyword);//查询的关键字
Map<String, Object> map = userService.list(params);
request.getSession().setAttribute("list", map.get("list"));
/**
* 编辑工资
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("salaryEdit")
public void edit(Salary vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
salaryService.update(vo);
this.redirectList(request, response);
}
/**
* 获取工资的详细信息(详情页面与编辑页面要显示该工资的详情)并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping({"salaryGet", "salaryEditPre"})
public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");//取出主键id
Salary vo = salaryService.get(id);
response.getWriter().println(com.alibaba.fastjson.JSONObject.toJSONString(vo));
}
/**
* 根据条件查询工资的列表并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("salaryList")
public void list(HttpServletResponse response, HttpServletRequest request) throws IOException {
this.redirectList(request, response);
}
String searchColumn = request.getParameter("searchColumn");
String keyword = request.getParameter("keyword");
Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
params.put("searchColumn", searchColumn);//要查询的列
params.put("keyword", keyword);//查询的关键字
Map<String, Object> map = salaryService.list(params);
request.getSession().setAttribute("list", map.get("list"));
Integer totalRecord = (Integer) map.get("totalCount");//根据查询条件取出对应的总记录数,用于分页
String pageNum = request.getParameter("pageNum");//封装分页参数
com.demo.util.PageBean<Object> pb = new com.demo.util.PageBean(Integer.valueOf(pageNum != null ? pageNum : "1"), totalRecord);
params.put("startIndex", pb.getStartIndex());
params.put("pageSize", pb.getPageSize());
List list = (List) salaryService.list(params).get("list");//根据分页参数startIndex、pageSize查询出来的最终结果list
pb.setServlet("salaryList");
pb.setSearchColumn(searchColumn);
pb.setKeyword(keyword);
pb.setList(list);
request.getSession().setAttribute("pageBean", pb);
request.getSession().setAttribute("list", pb.getList());
response.sendRedirect("salary_list.jsp");
}
}
@Controller
@RequestMapping
@Controller
@RequestMapping
public class NoticeController {
@Autowired
private NoticeService noticeService;
/**
* 增加公告
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("noticeAdd")
public void add(Notice vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
//调用Service层的增加(insert)方法
noticeService.insert(vo);
this.redirectList(request, response);
}
/**
* 删除公告
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("noticeDelete")
public void delete(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");
noticeService.delete(Arrays.asList(id));
this.redirectList(request, response);
*/
@RequestMapping("userEdit")
public void edit(User vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
userService.update(vo);
this.redirectList(request, response);
}
/**
* 获取用户的详细信息(详情页面与编辑页面要显示该用户的详情)并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping({"userGet", "userEditPre"})
public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");//取出主键id
User vo = userService.get(id);
response.getWriter().println(com.alibaba.fastjson.JSONObject.toJSONString(vo));
}
/**
* 根据条件查询用户的列表并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("userList")
public void list(HttpServletResponse response, HttpServletRequest request) throws IOException {
this.redirectList(request, response);
}
/**
* 跳转到列表页面
*
* @param request
* @param response
*/
private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {
//查询列和关键字
String searchColumn = request.getParameter("searchColumn");
String keyword = request.getParameter("keyword");
Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
params.put("searchColumn", searchColumn);//要查询的列
* 编辑公告
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("noticeEdit")
public void edit(Notice vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
noticeService.update(vo);
this.redirectList(request, response);
}
/**
* 获取公告的详细信息(详情页面与编辑页面要显示该公告的详情)并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping({"noticeGet", "noticeEditPre"})
public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");//取出主键id
Notice vo = noticeService.get(id);
response.getWriter().println(com.alibaba.fastjson.JSONObject.toJSONString(vo));
}
/**
* 根据条件查询公告的列表并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("noticeList")
public void list(HttpServletResponse response, HttpServletRequest request) throws IOException {
this.redirectList(request, response);
}
/**
* 跳转到列表页面
*
* @param request
* @param response
*/
private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {
//查询列和关键字
String searchColumn = request.getParameter("searchColumn");
String keyword = request.getParameter("keyword");
Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
params.put("searchColumn", searchColumn);//要查询的列
params.put("keyword", keyword);//查询的关键字
* @param request
* @throws IOException
*/
@RequestMapping("userDelete")
public void delete(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");
userService.delete(Arrays.asList(id));
this.redirectList(request, response);
}
/**
* 编辑用户
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("userEdit")
public void edit(User vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
userService.update(vo);
this.redirectList(request, response);
}
/**
* 获取用户的详细信息(详情页面与编辑页面要显示该用户的详情)并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping({"userGet", "userEditPre"})
public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");//取出主键id
User vo = userService.get(id);
response.getWriter().println(com.alibaba.fastjson.JSONObject.toJSONString(vo));
}
/**
* 根据条件查询用户的列表并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("userList")
public void list(HttpServletResponse response, HttpServletRequest request) throws IOException {
this.redirectList(request, response);
}
/**
* 跳转到列表页面
*
* @param request
@RequestMapping({"deptGet", "deptEditPre"})
public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");//取出主键id
Dept vo = deptService.get(id);
response.getWriter().println(com.alibaba.fastjson.JSONObject.toJSONString(vo));
}
/**
* 根据条件查询部门的列表并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("deptList")
public void list(HttpServletResponse response, HttpServletRequest request) throws IOException {
this.redirectList(request, response);
}
/**
* 跳转到列表页面
*
* @param request
* @param response
*/
private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {
//查询列和关键字
String searchColumn = request.getParameter("searchColumn");
String keyword = request.getParameter("keyword");
Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
params.put("searchColumn", searchColumn);//要查询的列
params.put("keyword", keyword);//查询的关键字
Map<String, Object> map = deptService.list(params);
request.getSession().setAttribute("list", map.get("list"));
Integer totalRecord = (Integer) map.get("totalCount");//根据查询条件取出对应的总记录数,用于分页
String pageNum = request.getParameter("pageNum");//封装分页参数
com.demo.util.PageBean<Object> pb = new com.demo.util.PageBean(Integer.valueOf(pageNum != null ? pageNum : "1"), totalRecord);
params.put("startIndex", pb.getStartIndex());
params.put("pageSize", pb.getPageSize());
List list = (List) deptService.list(params).get("list");//根据分页参数startIndex、pageSize查询出来的最终结果list
pb.setServlet("deptList");
pb.setSearchColumn(searchColumn);
@RequestMapping("deptDelete")
public void delete(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");
deptService.delete(Arrays.asList(id));
this.redirectList(request, response);
}
/**
* 编辑部门
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("deptEdit")
public void edit(Dept vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
deptService.update(vo);
this.redirectList(request, response);
}
/**
* 获取部门的详细信息(详情页面与编辑页面要显示该部门的详情)并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping({"deptGet", "deptEditPre"})
public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");//取出主键id
Dept vo = deptService.get(id);
response.getWriter().println(com.alibaba.fastjson.JSONObject.toJSONString(vo));
}
/**
* 根据条件查询部门的列表并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("deptList")
public void list(HttpServletResponse response, HttpServletRequest request) throws IOException {
this.redirectList(request, response);
}
/**
* 跳转到列表页面
*
* @param request
* @param response
*/
private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {