当前位置:   article > 正文

基于SSM+MySQL+Boostrap简单的员工信息管理系统_人员信息管理用什么数据库

人员信息管理用什么数据库

修改信息

部分代码

技术描述

开发工具: Idea/Eclipse
数据库: mysql
Jar包仓库: Maven
前段框架:jquery/Jsp
后端框架: Spring+SpringMVC+Mybatis

资料说明

基于SSM+MySQL+Boostrap简单的员工信息管理系统,简单的员工信息增删改查初级代码。

  1. package com.crud.controller;
  2. import java.util.ArrayList;
  3. import java.util.HashMap;
  4. import java.util.List;
  5. import java.util.Map;
  6. import javax.validation.Valid;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.stereotype.Controller;
  9. import org.springframework.ui.Model;
  10. import org.springframework.validation.BindingResult;
  11. import org.springframework.validation.FieldError;
  12. import org.springframework.web.bind.annotation.PathVariable;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.RequestMethod;
  15. import org.springframework.web.bind.annotation.RequestParam;
  16. import org.springframework.web.bind.annotation.ResponseBody;
  17. import com.crud.bean.Employee;
  18. import com.crud.bean.Msg;
  19. import com.crud.service.EmployeeService;
  20. import com.github.pagehelper.PageHelper;
  21. import com.github.pagehelper.PageInfo;
  22. /**
  23. * 处理员工信息CRUD请求
  24. *
  25. * @author copywang
  26. *
  27. */
  28. @Controller
  29. public class EmployeeController {
  30. @Autowired
  31. EmployeeService employeeService;
  32. /**
  33. * 导入jackson包 把对象转换成JSON字符串 第二稿 支持移动设备
  34. *
  35. * @param pn
  36. * @return
  37. */
  38. @RequestMapping("/emps")
  39. @ResponseBody
  40. public Msg getEmpsWithJson(@RequestParam(value = "pn", defaultValue = "1") Integer pn) {
  41. // 引入PageHelper分页插件
  42. // 查询前调用,传入页码和记录数
  43. PageHelper.startPage(pn, 5);
  44. // startPage紧跟着的这个查询就是一个分页查询
  45. List<Employee> emps = employeeService.getAll();
  46. // PageInfo包装查询结果,封装了详细的分页信息和详细数据
  47. // 连续显示5页
  48. PageInfo pageInfo = new PageInfo(emps, 5);
  49. return Msg.success().add("pageInfo", pageInfo);
  50. }
  51. /**
  52. * 展示list.jsp页面 查询员工数据(分页查询) 第一稿 用静态方法刷新的页面,支持浏览器
  53. *
  54. * @return
  55. */
  56. // @RequestMapping("/emps")
  57. public String getEmps(@RequestParam(value = "pn", defaultValue = "1") Integer pn, Model model) {
  58. // 引入PageHelper分页插件
  59. // 查询前调用,传入页码和记录数
  60. PageHelper.startPage(pn, 5);
  61. // startPage紧跟着的这个查询就是一个分页查询
  62. List<Employee> emps = employeeService.getAll();
  63. // PageInfo包装查询结果,封装了详细的分页信息和详细数据
  64. // 连续显示5页
  65. PageInfo pageInfo = new PageInfo(emps, 5);
  66. // 把PageInfo交给页面即可
  67. model.addAttribute("pageInfo", pageInfo);
  68. return "list";
  69. }
  70. /**
  71. * 校验用户名是否被占用
  72. *
  73. * @param empName
  74. * @return
  75. */
  76. @RequestMapping(value = "/checkuser", method = RequestMethod.POST)
  77. @ResponseBody
  78. public Msg checkuser(@RequestParam("empName") String empName) {
  79. // 判断用户名是否符合正则表达式
  80. String regex = "(^[A-Za-z0-9]{6,16}$)|(^[\\u2E80-\\u9FFF]{2,5}$)";
  81. if (!empName.matches(regex)) {
  82. // System.out.println(empName.matches(regex));
  83. return Msg.fail().add("va_msg", "名字必须是2-5个中文或者6-16位英文数字组合");
  84. }
  85. if (employeeService.checkuser(empName)) {
  86. return Msg.success();
  87. } else {
  88. return Msg.fail().add("va_msg", "用户名不可用");
  89. }
  90. }
  91. /**
  92. * 保存员工信息
  93. *
  94. */
  95. @RequestMapping(value = "/emp", method = RequestMethod.POST)
  96. @ResponseBody
  97. public Msg saveEmp(@Valid Employee employee, BindingResult result) {
  98. if (result.hasErrors()) {
  99. Map<String, Object> map = new HashMap<String, Object>();
  100. List<FieldError> fieldErrors = result.getFieldErrors();
  101. for (FieldError fieldError : fieldErrors) {
  102. map.put(fieldError.getField(), fieldError.getDefaultMessage());
  103. }
  104. return Msg.fail().add("errorFields", map);
  105. } else {
  106. employeeService.saveEmp(employee);
  107. return Msg.success();
  108. }
  109. }
  110. /**
  111. * 查询员工信息
  112. *
  113. */
  114. @RequestMapping(value = "/emp/{id}", method = RequestMethod.GET)
  115. @ResponseBody
  116. public Msg getEmp(@PathVariable("id") Integer id) {
  117. Employee emp = employeeService.getEmp(id);
  118. return Msg.success().add("emp", emp);
  119. }
  120. /**
  121. * 修改员工ID
  122. */
  123. @RequestMapping(value = "/emp/{empId}", method = RequestMethod.PUT)
  124. @ResponseBody
  125. public Msg getEmp(Employee employee) {
  126. employeeService.updateEmp(employee);
  127. return Msg.success();
  128. }
  129. /*
  130. * //单个删除员工信息
  131. *
  132. * @RequestMapping(value="/emp/{id}",method=RequestMethod.DELETE)
  133. *
  134. * @ResponseBody public Msg deleteEmpById(@PathVariable("id")Integer id) {
  135. * employeeService.deleteEmp(id); return Msg.success(); }
  136. */
  137. /**
  138. * 批量删除员工信息:1-2-3 单个:1
  139. */
  140. @RequestMapping(value = "/emp/{ids}", method = RequestMethod.DELETE)
  141. @ResponseBody
  142. public Msg deleteEmpById(@PathVariable("ids") String ids) {
  143. if (ids.contains("-")) {
  144. String[] strIds = ids.split("-");
  145. /*
  146. * 一种实现 for (String str : strIds) {
  147. * employeeService.deleteEmp(Integer.parseInt(str)); }
  148. */
  149. // 另一种实现
  150. List<Integer> del_ids = new ArrayList<Integer>();
  151. for (String str : strIds) {
  152. del_ids.add(Integer.parseInt(str));
  153. }
  154. employeeService.deleteBatchEmp(del_ids);
  155. } else {
  156. employeeService.deleteEmp(Integer.parseInt(ids));
  157. }
  158. return Msg.success();
  159. }
  160. @RequestMapping("/emp/query")
  161. public String toQueryPage() {
  162. return "query";
  163. }
  164. /**
  165. * 查询功能的查询员工信息 查询出来的员工数据分页显示
  166. */
  167. @RequestMapping(value = "/queryEmps", method = RequestMethod.POST)
  168. @ResponseBody
  169. public Msg queryEmp(@RequestParam(value = "pn", defaultValue = "1") Integer pn,
  170. Employee employee) {
  171. // System.out.println(employee);
  172. PageHelper.startPage(pn, 20);
  173. List<Employee> emplist = employeeService.queryEmp(employee);
  174. // PageInfo包装查询结果,封装了详细的分页信息和详细数据
  175. // 连续显示5页
  176. PageInfo pageInfo = new PageInfo(emplist, 5);
  177. return Msg.success().add("pageInfo", pageInfo);
  178. }
  179. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/476457
推荐阅读
相关标签
  

闽ICP备14008679号