基于javaweb+mysql的ssm+maven工作日志管理系统(JavaWeb MySQL JSP Bootstrap Servlet SSM SpringBoot)
私信源码获取及调试交流
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
技术框架
JavaBean MVC JSP SSM(Spring SpringMVC MyBatis) Maven MySQL CSS JavaScript Bootstrap.
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
登录、注册、退出、用户模块、公告模块、员工模块、日志模块的增删改查管理
eclipse/MyEclipse运行:
idea运行:
@Controller
@RequestMapping
public class RizhiController {
@Autowired
private RizhiService rizhiService;
/**
* 增加日志
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("rizhiAdd")
public void add(Rizhi vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
//调用Service层的增加(insert)方法
rizhiService.insert(vo);
this.redirectList(request, response);
}
/**
* 删除日志
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("rizhiDelete")
public void delete(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");
rizhiService.delete(Arrays.asList(id));
this.redirectList(request, response);
}
/**
* 编辑日志
*
* @param response
* @param request
* @param request
* @throws IOException
*/
@RequestMapping("rizhiEdit")
public void edit(Rizhi vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
rizhiService.update(vo);
this.redirectList(request, response);
}
/**
* 获取日志的详细信息(详情页面与编辑页面要显示该日志的详情)并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping({"rizhiGet", "rizhiEditPre"})
public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");//取出主键id
Rizhi vo = rizhiService.get(id);
request.getSession().setAttribute("vo", vo);
String to = request.getRequestURI().toLowerCase().contains("get") ? "info" : "edit";//判断是去详情显示页面还是编辑页面
response.sendRedirect("rizhi_" + to + ".jsp");
}
/**
* 根据条件查询日志的列表并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("rizhiList")
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);//查询的关键字
Rizhi vo = rizhiService.get(id);
request.getSession().setAttribute("vo", vo);
String to = request.getRequestURI().toLowerCase().contains("get") ? "info" : "edit";//判断是去详情显示页面还是编辑页面
response.sendRedirect("rizhi_" + to + ".jsp");
}
/**
* 根据条件查询日志的列表并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("rizhiList")
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 = rizhiService.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) rizhiService.list(params).get("list");//根据分页参数startIndex、pageSize查询出来的最终结果list
pb.setServlet("rizhiList");
pb.setSearchColumn(searchColumn);
pb.setKeyword(keyword);
*/
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 = rizhiService.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) rizhiService.list(params).get("list");//根据分页参数startIndex、pageSize查询出来的最终结果list
pb.setServlet("rizhiList");
pb.setSearchColumn(searchColumn);
pb.setKeyword(keyword);
pb.setList(list);
request.getSession().setAttribute("pageBean", pb);
request.getSession().setAttribute("list", pb.getList());
response.sendRedirect("rizhi_list.jsp");
}
}
@Controller
@RequestMapping
pb.setKeyword(keyword);
pb.setList(list);
request.getSession().setAttribute("pageBean", pb);
request.getSession().setAttribute("list", pb.getList());
response.sendRedirect("user_list.jsp");
}
}
@Controller
@RequestMapping
public class EmpController {
@Autowired
private EmpService empService;
/**
* 增加员工
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("empAdd")
public void add(Emp vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
//调用Service层的增加(insert)方法
empService.insert(vo);
this.redirectList(request, response);
}
response.sendRedirect("rizhi_" + to + ".jsp");
}
/**
* 根据条件查询日志的列表并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("rizhiList")
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 = rizhiService.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) rizhiService.list(params).get("list");//根据分页参数startIndex、pageSize查询出来的最终结果list
pb.setServlet("rizhiList");
pb.setSearchColumn(searchColumn);
pb.setKeyword(keyword);
pb.setList(list);
request.getSession().setAttribute("pageBean", pb);
request.getSession().setAttribute("list", pb.getList());
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);
request.getSession().setAttribute("vo", vo);
String to = request.getRequestURI().toLowerCase().contains("get") ? "info" : "edit";//判断是去详情显示页面还是编辑页面
response.sendRedirect("user_" + to + ".jsp");
}
/**
* 根据条件查询用户的列表并跳转回页面
*
* @param response
* @param request
* @throws IOException
params.put("keyword", keyword);//查询的关键字
Map<String, Object> map = rizhiService.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) rizhiService.list(params).get("list");//根据分页参数startIndex、pageSize查询出来的最终结果list
pb.setServlet("rizhiList");
pb.setSearchColumn(searchColumn);
pb.setKeyword(keyword);
pb.setList(list);
request.getSession().setAttribute("pageBean", pb);
request.getSession().setAttribute("list", pb.getList());
response.sendRedirect("rizhi_list.jsp");
}
}
@Controller
@RequestMapping
public class UserController {
@Autowired
private UserService userService;
/**
* 增加用户
empService.delete(Arrays.asList(id));
this.redirectList(request, response);
}
/**
* 编辑员工
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("empEdit")
public void edit(Emp vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
empService.update(vo);
this.redirectList(request, response);
}
/**
* 获取员工的详细信息(详情页面与编辑页面要显示该员工的详情)并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping({"empGet", "empEditPre"})
public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");//取出主键id
Emp vo = empService.get(id);
request.getSession().setAttribute("vo", vo);
String to = request.getRequestURI().toLowerCase().contains("get") ? "info" : "edit";//判断是去详情显示页面还是编辑页面
response.sendRedirect("emp_" + to + ".jsp");
}
/**
* 根据条件查询员工的列表并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("empList")
public void list(HttpServletResponse response, HttpServletRequest request) throws IOException {
this.redirectList(request, response);
}
response.sendRedirect("notice_list.jsp");
}
}
@Controller
@RequestMapping
public class RizhiController {
@Autowired
private RizhiService rizhiService;
/**
* 增加日志
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("rizhiAdd")
public void add(Rizhi vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
//调用Service层的增加(insert)方法
rizhiService.insert(vo);
this.redirectList(request, response);
}
/**
pb.setServlet("empList");
pb.setSearchColumn(searchColumn);
pb.setKeyword(keyword);
pb.setList(list);
request.getSession().setAttribute("pageBean", pb);
request.getSession().setAttribute("list", pb.getList());
response.sendRedirect("emp_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) {
if (uri.toLowerCase().contains(action.toLowerCase())) {
return true;
}
}
if (session.getAttribute("loginUser") == null) {
session.setAttribute("alert_msg", "错误:请先登录!");
response.sendRedirect("login.jsp");
return false;
}
}
@RequestMapping("authLogout")
public void logout(HttpServletResponse response, HttpServletRequest request) throws IOException {
HttpSession session = request.getSession();
User user = (User) session.getAttribute("loginUser");
if (user != null) {
session.removeAttribute("loginUser");
}
response.sendRedirect("login.jsp");
}
@RequestMapping("authValidationCode")
public void validationCode(HttpServletResponse response, HttpServletRequest request) throws IOException {
String codeChars = "0123456789";// 图形验证码的字符集合,系统将随机从这个字符串中选择一些字符作为验证码
// 获得验证码集合的长度
int charsLength = codeChars.length();
// 下面三条记录是关闭客户端浏览器的缓冲区
// 这三条语句都可以关闭浏览器的缓冲区,但是由于浏览器的版本不同,对这三条语句的支持也不同
// 因此,为了保险起见,建议同时使用这三条语句来关闭浏览器的缓冲区
response.setHeader("ragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
// 设置图形验证码的长和宽(图形的大小)
int width = 90, height = 20;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();// 获得用于输出文字的Graphics对象
Random random = new Random();
g.setColor(getRandomColor(180, 250));// 随机设置要填充的颜色
g.fillRect(0, 0, width, height);// 填充图形背景
// 设置初始字体
g.setFont(new Font("Times New Roman", Font.ITALIC, height));
g.setColor(getRandomColor(120, 180));// 随机设置字体颜色
// 用于保存最后随机生成的验证码
StringBuilder validationCode = new StringBuilder();
// 验证码的随机字体
String[] fontNames = {"Times New Roman", "Book antiqua", "Arial"};
for (int i = 0; i < 4; i++) {
// 随机设置当前验证码的字符的字体
g.setFont(new Font(fontNames[random.nextInt(3)], Font.ITALIC, height));
// 随机获得当前验证码的字符
char codeChar = codeChars.charAt(random.nextInt(charsLength));
validationCode.append(codeChar);
// 随机设置当前验证码字符的颜色
g.setColor(getRandomColor(10, 100));
/**
* 编辑用户
*
* @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);
request.getSession().setAttribute("vo", vo);
String to = request.getRequestURI().toLowerCase().contains("get") ? "info" : "edit";//判断是去详情显示页面还是编辑页面
response.sendRedirect("user_" + to + ".jsp");
}
/**
* 根据条件查询用户的列表并跳转回页面
*
* @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 {
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("empEdit")
public void edit(Emp vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
empService.update(vo);
this.redirectList(request, response);
}
/**
* 获取员工的详细信息(详情页面与编辑页面要显示该员工的详情)并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping({"empGet", "empEditPre"})
public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");//取出主键id
Emp vo = empService.get(id);
request.getSession().setAttribute("vo", vo);
String to = request.getRequestURI().toLowerCase().contains("get") ? "info" : "edit";//判断是去详情显示页面还是编辑页面
response.sendRedirect("emp_" + to + ".jsp");
}
/**
* 根据条件查询员工的列表并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("empList")
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 = empService.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) empService.list(params).get("list");//根据分页参数startIndex、pageSize查询出来的最终结果list
pb.setServlet("empList");
pb.setSearchColumn(searchColumn);
pb.setKeyword(keyword);
pb.setList(list);
request.getSession().setAttribute("pageBean", pb);
request.getSession().setAttribute("list", pb.getList());
response.sendRedirect("emp_list.jsp");
}
}
/**
* 拦截器
*/
public class LoginInterceptor implements HandlerInterceptor {
//@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o) throws Exception {
HttpSession session = request.getSession();
//移除错误提示
@Controller
@RequestMapping
public class EmpController {
@Autowired
private EmpService empService;
/**
* 增加员工
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("empAdd")
public void add(Emp vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
//调用Service层的增加(insert)方法
empService.insert(vo);
this.redirectList(request, response);
}
/**
* 删除员工
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("empDelete")
public void delete(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");
empService.delete(Arrays.asList(id));
this.redirectList(request, response);
}
request.getSession().setAttribute("pageBean", pb);
request.getSession().setAttribute("list", pb.getList());
response.sendRedirect("user_list.jsp");
}
}
@Controller
@RequestMapping
public class EmpController {
@Autowired
private EmpService empService;
/**
* 增加员工
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("empAdd")
public void add(Emp vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
//调用Service层的增加(insert)方法
empService.insert(vo);
this.redirectList(request, response);
}
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("rizhiDelete")
public void delete(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");
rizhiService.delete(Arrays.asList(id));
this.redirectList(request, response);
}
/**
* 编辑日志
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("rizhiEdit")
public void edit(Rizhi vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
rizhiService.update(vo);
this.redirectList(request, response);
}
/**
* 获取日志的详细信息(详情页面与编辑页面要显示该日志的详情)并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping({"rizhiGet", "rizhiEditPre"})
public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");//取出主键id
Rizhi vo = rizhiService.get(id);
request.getSession().setAttribute("vo", vo);
String to = request.getRequestURI().toLowerCase().contains("get") ? "info" : "edit";//判断是去详情显示页面还是编辑页面
response.sendRedirect("rizhi_" + to + ".jsp");
}
/**
* 根据条件查询日志的列表并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("rizhiList")