当前位置:   article > 正文

Java项目:美容院后台管理系统(java+SpringBoot+JSP+LayUI+maven+mysql)_jsp+layui后台系统模板

jsp+layui后台系统模板

源码获取:博客首页 "资源" 里下载!

项目介绍

本项目为美容院后台管理系统
操作员包含以下功能:操作员登陆,操作员首页,会员列表,添加会员,添加美容产品,购买商品,添加护理记录,客户购买记录,护理记录,销售记录等功能。

环境需要

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版本;

技术栈

1. 后端:SpringBoot

2. 前端:HTML+CSS+JavaScript+jsp

使用说明

1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中application.yml配置文件中的数据库配置改为自己的配置;
4. 运行项目,输入localhost:8080/ 登录

 

 

 

 

 

 

 后台用户管理控制器:

  1. /**
  2. * 后台用户管理控制器
  3. * @author yy
  4. *
  5. */
  6. @RequestMapping("/admin/user")
  7. @Controller
  8. public class UserController {
  9. @Autowired
  10. private UserService userService;
  11. @Autowired
  12. private RoleService roleService;
  13. @Autowired
  14. private OperaterLogService operaterLogService;
  15. /**
  16. * 用户列表页面
  17. * @param model
  18. * @param user
  19. * @param pageBean
  20. * @return
  21. */
  22. @RequestMapping(value="/list")
  23. public String list(Model model,User user,PageBean<User> pageBean){
  24. model.addAttribute("title", "用户列表");
  25. model.addAttribute("username", user.getUsername());
  26. model.addAttribute("pageBean", userService.findList(user, pageBean));
  27. return "admin/user/list";
  28. }
  29. /**
  30. * 新增用户页面
  31. * @param model
  32. * @return
  33. */
  34. @RequestMapping(value="/add",method=RequestMethod.GET)
  35. public String add(Model model){
  36. model.addAttribute("roles", roleService.findByType(Role.ADMIN_ROLE_TYPE_ADMIN));
  37. return "admin/user/add";
  38. }
  39. /**
  40. * 用户添加表单提交处理
  41. * @param user
  42. * @return
  43. */
  44. @RequestMapping(value="/add",method=RequestMethod.POST)
  45. @ResponseBody
  46. public Result<Boolean> add(User user){
  47. //用统一验证实体方法验证是否合法
  48. CodeMsg validate = ValidateEntityUtil.validate(user);
  49. if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
  50. return Result.error(validate);
  51. }
  52. if(user.getRole() == null || user.getRole().getId() == null){
  53. return Result.error(CodeMsg.ADMIN_USER_ROLE_EMPTY);
  54. }
  55. //判断用户名是否存在
  56. if(userService.isExistUsername(user.getUsername(), 0l)){
  57. return Result.error(CodeMsg.ADMIN_USERNAME_EXIST);
  58. }
  59. //到这说明一切符合条件,进行数据库新增
  60. if(userService.save(user) == null){
  61. return Result.error(CodeMsg.ADMIN_USE_ADD_ERROR);
  62. }
  63. operaterLogService.add("添加用户,用户名:" + user.getUsername());
  64. return Result.success(true);
  65. }
  66. /**
  67. * 用户编辑页面
  68. * @param model
  69. * @return
  70. */
  71. @RequestMapping(value="/edit",method=RequestMethod.GET)
  72. public String edit(Model model,@RequestParam(name="id",required=true)Long id){
  73. model.addAttribute("roles", roleService.findByType(Role.ADMIN_ROLE_TYPE_ADMIN));
  74. model.addAttribute("user", userService.find(id));
  75. return "admin/user/edit";
  76. }
  77. /**
  78. * 编辑用户信息表单提交处理
  79. * @param user
  80. * @return
  81. */
  82. @RequestMapping(value="/edit",method=RequestMethod.POST)
  83. @ResponseBody
  84. public Result<Boolean> edit(User user){
  85. //用统一验证实体方法验证是否合法
  86. CodeMsg validate = ValidateEntityUtil.validate(user);
  87. if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
  88. return Result.error(validate);
  89. }
  90. if(user.getRole() == null || user.getRole().getId() == null){
  91. return Result.error(CodeMsg.ADMIN_USER_ROLE_EMPTY);
  92. }
  93. if(user.getId() == null || user.getId().longValue() <= 0){
  94. return Result.error(CodeMsg.ADMIN_USE_NO_EXIST);
  95. }
  96. if(userService.isExistUsername(user.getUsername(), user.getId())){
  97. return Result.error(CodeMsg.ADMIN_USERNAME_EXIST);
  98. }
  99. //到这说明一切符合条件,进行数据库保存
  100. User findById = userService.find(user.getId());
  101. //讲提交的用户信息指定字段复制到已存在的user对象中,该方法会覆盖新字段内容
  102. BeanUtils.copyProperties(user, findById, "id","createTime","updateTime");
  103. if(userService.save(findById) == null){
  104. return Result.error(CodeMsg.ADMIN_USE_EDIT_ERROR);
  105. }
  106. operaterLogService.add("编辑用户,用户名:" + user.getUsername());
  107. return Result.success(true);
  108. }
  109. /**
  110. * 删除用户
  111. * @param id
  112. * @return
  113. */
  114. @RequestMapping(value="/delete",method=RequestMethod.POST)
  115. @ResponseBody
  116. public Result<Boolean> delete(@RequestParam(name="id",required=true)Long id){
  117. try {
  118. userService.delete(id);
  119. } catch (Exception e) {
  120. return Result.error(CodeMsg.ADMIN_USE_DELETE_ERROR);
  121. }
  122. operaterLogService.add("删除用户,用户ID:" + id);
  123. return Result.success(true);
  124. }
  125. }

后台角色管理控制器:

  1. /**
  2. * 后台角色管理控制器
  3. * @author yy
  4. *
  5. */
  6. @RequestMapping("/admin/role")
  7. @Controller
  8. public class RoleController {
  9. private Logger log = LoggerFactory.getLogger(RoleController.class);
  10. @Autowired
  11. private MenuService menuService;
  12. @Autowired
  13. private OperaterLogService operaterLogService;
  14. @Autowired
  15. private RoleService roleService;
  16. /**
  17. * 分页搜索角色列表
  18. * @param model
  19. * @param role
  20. * @param pageBean
  21. * @return
  22. */
  23. @RequestMapping(value="/list")
  24. public String list(Model model,Role role,PageBean<Role> pageBean){
  25. model.addAttribute("title", "角色列表");
  26. model.addAttribute("name", role.getName());
  27. model.addAttribute("pageBean", roleService.findByName(role, pageBean));
  28. return "admin/role/list";
  29. }
  30. /**
  31. * 角色添加页面
  32. * @param model
  33. * @return
  34. */
  35. @RequestMapping(value="/add",method=RequestMethod.GET)
  36. public String add(Model model){
  37. List<Menu> findAll = menuService.findAll();
  38. model.addAttribute("topMenus",MenuUtil.getTopMenus(findAll));
  39. model.addAttribute("secondMenus",MenuUtil.getSecondMenus(findAll));
  40. model.addAttribute("thirdMenus",MenuUtil.getThirdMenus(findAll));
  41. return "admin/role/add";
  42. }
  43. /**
  44. * 角色添加表单提交处理
  45. * @param role
  46. * @return
  47. */
  48. @RequestMapping(value="/add",method=RequestMethod.POST)
  49. @ResponseBody
  50. public Result<Boolean> add(Role role){
  51. //用统一验证实体方法验证是否合法
  52. CodeMsg validate = ValidateEntityUtil.validate(role);
  53. if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
  54. return Result.error(validate);
  55. }
  56. if(roleService.save(role) == null){
  57. return Result.error(CodeMsg.ADMIN_ROLE_ADD_ERROR);
  58. }
  59. log.info("添加角色【"+role+"】");
  60. operaterLogService.add("添加角色【"+role.getName()+"】");
  61. return Result.success(true);
  62. }
  63. /**
  64. * 角色编辑页面
  65. * @param id
  66. * @param model
  67. * @return
  68. */
  69. @RequestMapping(value="/edit",method=RequestMethod.GET)
  70. public String edit(@RequestParam(name="id",required=true)Long id,Model model){
  71. List<Menu> findAll = menuService.findAll();
  72. model.addAttribute("topMenus",MenuUtil.getTopMenus(findAll));
  73. model.addAttribute("secondMenus",MenuUtil.getSecondMenus(findAll));
  74. model.addAttribute("thirdMenus",MenuUtil.getThirdMenus(findAll));
  75. Role role = roleService.find(id);
  76. model.addAttribute("role", role);
  77. model.addAttribute("authorities",JSONArray.toJSON(role.getAuthorities()).toString());
  78. return "admin/role/edit";
  79. }
  80. /**
  81. * 角色修改表单提交处理
  82. * @param role
  83. * @return
  84. */
  85. @RequestMapping(value="/edit",method=RequestMethod.POST)
  86. @ResponseBody
  87. public Result<Boolean> edit(Role role){
  88. //用统一验证实体方法验证是否合法
  89. CodeMsg validate = ValidateEntityUtil.validate(role);
  90. if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
  91. return Result.error(validate);
  92. }
  93. Role existRole = roleService.find(role.getId());
  94. if(existRole == null){
  95. return Result.error(CodeMsg.ADMIN_ROLE_NO_EXIST);
  96. }
  97. existRole.setName(role.getName());
  98. existRole.setRemark(role.getRemark());
  99. existRole.setStatus(role.getStatus());
  100. existRole.setAuthorities(role.getAuthorities());
  101. existRole.setType(role.getType());
  102. if(roleService.save(existRole) == null){
  103. return Result.error(CodeMsg.ADMIN_ROLE_EDIT_ERROR);
  104. }
  105. log.info("编辑角色【"+role+"】");
  106. operaterLogService.add("编辑角色【"+role.getName()+"】");
  107. return Result.success(true);
  108. }
  109. /**
  110. * 删除角色
  111. * @param request
  112. * @param id
  113. * @return
  114. */
  115. @RequestMapping(value="delete",method=RequestMethod.POST)
  116. @ResponseBody
  117. public Result<Boolean> delete(@RequestParam(name="id",required=true)Long id){
  118. try {
  119. roleService.delete(id);
  120. } catch (Exception e) {
  121. // TODO: handle exception
  122. return Result.error(CodeMsg.ADMIN_ROLE_DELETE_ERROR);
  123. }
  124. log.info("编辑角色ID【"+id+"】");
  125. operaterLogService.add("删除角色ID【"+id+"】");
  126. return Result.success(true);
  127. }
  128. }

系统控制器:

  1. /**
  2. * 系统控制器
  3. * @author yy
  4. *
  5. */
  6. @RequestMapping("/system")
  7. @Controller
  8. public class SystemController {
  9. @Autowired
  10. private OperaterLogService operaterLogService;
  11. @Autowired
  12. private UserService userService;
  13. @Autowired
  14. private DatabaseBakService databaseBakService;
  15. @Autowired
  16. private ItemService itemService;
  17. @Autowired
  18. private PeopleService peopleService;
  19. @Autowired
  20. private OrderAuthService orderAuthService;
  21. @Autowired
  22. private StaffService staffService;
  23. /* @Value("${show.tips.text}")
  24. private String showTipsText;
  25. @Value("${show.tips.url.text}")
  26. private String showTipsUrlText;
  27. @Value("${show.tips.btn.text}")
  28. private String showTipsBtnText;
  29. @Value("${show.tips.url}")
  30. private String showTipsUtl;*/
  31. private Logger log = LoggerFactory.getLogger(SystemController.class);
  32. /**
  33. * 登录页面
  34. * @param model
  35. * @return
  36. */
  37. @RequestMapping(value="/login",method=RequestMethod.GET)
  38. public String login(Model model){
  39. return "admin/system/login";
  40. }
  41. /**
  42. * 用户登录提交表单处理方法
  43. * @param request
  44. * @param user
  45. * @param cpacha
  46. * @return
  47. */
  48. @RequestMapping(value="/login",method=RequestMethod.POST)
  49. @ResponseBody
  50. public Result<Boolean> login(HttpServletRequest request,User user,String cpacha){
  51. if(user == null){
  52. return Result.error(CodeMsg.DATA_ERROR);
  53. }
  54. //用统一验证实体方法验证是否合法
  55. CodeMsg validate = ValidateEntityUtil.validate(user);
  56. if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
  57. return Result.error(validate);
  58. }
  59. //表示实体信息合法,开始验证验证码是否为空
  60. if(StringUtils.isEmpty(cpacha)){
  61. return Result.error(CodeMsg.CPACHA_EMPTY);
  62. }
  63. //说明验证码不为空,从session里获取验证码
  64. Object attribute = request.getSession().getAttribute("admin_login");
  65. if(attribute == null){
  66. return Result.error(CodeMsg.SESSION_EXPIRED);
  67. }
  68. //表示session未失效,进一步判断用户填写的验证码是否正确
  69. if(!cpacha.equalsIgnoreCase(attribute.toString())){
  70. return Result.error(CodeMsg.CPACHA_ERROR);
  71. }
  72. //表示验证码正确,开始查询数据库,检验密码是否正确
  73. User findByUsername = userService.findByUsername(user.getUsername());
  74. //判断是否为空
  75. if(findByUsername == null){
  76. return Result.error(CodeMsg.ADMIN_USERNAME_NO_EXIST);
  77. }
  78. //表示用户存在,进一步对比密码是否正确
  79. if(!findByUsername.getPassword().equals(user.getPassword())){
  80. return Result.error(CodeMsg.ADMIN_PASSWORD_ERROR);
  81. }
  82. //表示密码正确,接下来判断用户状态是否可用
  83. if(findByUsername.getStatus() == User.ADMIN_USER_STATUS_UNABLE){
  84. return Result.error(CodeMsg.ADMIN_USER_UNABLE);
  85. }
  86. //检查用户所属角色状态是否可用
  87. if(findByUsername.getRole() == null || findByUsername.getRole().getStatus() == Role.ADMIN_ROLE_STATUS_UNABLE){
  88. return Result.error(CodeMsg.ADMIN_USER_ROLE_UNABLE);
  89. }
  90. //检查用户所属角色的权限是否存在
  91. if(findByUsername.getRole().getAuthorities() == null || findByUsername.getRole().getAuthorities().size() == 0){
  92. return Result.error(CodeMsg.ADMIN_USER_ROLE_AUTHORITES_EMPTY);
  93. }
  94. //检查一切符合,可以登录,将用户信息存放至session
  95. request.getSession().setAttribute(SessionConstant.SESSION_USER_LOGIN_KEY, findByUsername);
  96. //销毁session中的验证码
  97. request.getSession().setAttribute("admin_login", null);
  98. //将登陆记录写入日志库
  99. operaterLogService.add("用户【"+user.getUsername()+"】于【" + StringUtil.getFormatterDate(new Date(), "yyyy-MM-dd HH:mm:ss") + "】登录系统!");
  100. log.info("用户成功登录,user = " + findByUsername);
  101. return Result.success(true);
  102. }
  103. /**
  104. * 登录成功后的系统主页
  105. * @param model
  106. * @return
  107. */
  108. @RequestMapping(value="/index")
  109. public String index(Model model){
  110. model.addAttribute("operatorLogs", operaterLogService.findLastestLog(10));
  111. model.addAttribute("userTotal", userService.total());
  112. model.addAttribute("operatorLogTotal", operaterLogService.total());
  113. model.addAttribute("databaseBackupTotal", databaseBakService.total());
  114. model.addAttribute("itemCount", itemService.count());
  115. model.addAttribute("peopleCount", peopleService.count());
  116. model.addAttribute("workerCount", staffService.countByType(Staff.WORKER));
  117. model.addAttribute("coachCount", staffService.countByType(Staff.COACH));
  118. model.addAttribute("onlineUserTotal", SessionListener.onlineUserCount);
  119. return "admin/system/index";
  120. }
  121. /**
  122. * 注销登录
  123. * @return
  124. */
  125. @RequestMapping(value="/logout")
  126. public String logout(){
  127. User loginedUser = SessionUtil.getLoginedUser();
  128. if(loginedUser != null){
  129. SessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY, null);
  130. }
  131. return "redirect:login";
  132. }
  133. /**
  134. * 无权限提示页面
  135. * @return
  136. */
  137. @RequestMapping(value="/no_right")
  138. public String noRight(){
  139. return "admin/system/no_right";
  140. }
  141. /**
  142. * 修改用户个人信息
  143. * @return
  144. */
  145. @RequestMapping(value="/update_userinfo",method=RequestMethod.GET)
  146. public String updateUserInfo(){
  147. return "admin/system/update_userinfo";
  148. }
  149. /**
  150. * 修改个人信息保存
  151. * @param user
  152. * @return
  153. */
  154. @RequestMapping(value="/update_userinfo",method=RequestMethod.POST)
  155. public String updateUserInfo(User user){
  156. User loginedUser = SessionUtil.getLoginedUser();
  157. loginedUser.setEmail(user.getEmail());
  158. loginedUser.setMobile(user.getMobile());
  159. loginedUser.setHeadPic(user.getHeadPic());
  160. //首先保存到数据库
  161. userService.save(loginedUser);
  162. //更新session里的值
  163. SessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY, loginedUser);
  164. return "redirect:update_userinfo";
  165. }
  166. /**
  167. * 修改密码页面
  168. * @return
  169. */
  170. @RequestMapping(value="/update_pwd",method=RequestMethod.GET)
  171. public String updatePwd(){
  172. return "admin/system/update_pwd";
  173. }
  174. /**
  175. * 修改密码表单提交
  176. * @param oldPwd
  177. * @param newPwd
  178. * @return
  179. */
  180. @RequestMapping(value="/update_pwd",method=RequestMethod.POST)
  181. @ResponseBody
  182. public Result<Boolean> updatePwd(@RequestParam(name="oldPwd",required=true)String oldPwd,
  183. @RequestParam(name="newPwd",required=true)String newPwd
  184. ){
  185. User loginedUser = SessionUtil.getLoginedUser();
  186. if(!loginedUser.getPassword().equals(oldPwd)){
  187. return Result.error(CodeMsg.ADMIN_USER_UPDATE_PWD_ERROR);
  188. }
  189. if(StringUtils.isEmpty(newPwd)){
  190. return Result.error(CodeMsg.ADMIN_USER_UPDATE_PWD_EMPTY);
  191. }
  192. if (newPwd.length() < 4){
  193. return Result.error(CodeMsg.ADMIN_USER_UPDATE_PWD_LENGTH);
  194. }
  195. loginedUser.setPassword(newPwd);
  196. //保存数据库
  197. userService.save(loginedUser);
  198. //更新session
  199. SessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY, loginedUser);
  200. return Result.success(true);
  201. }
  202. /**
  203. * 日志管理列表
  204. * @param model
  205. * @param operaterLog
  206. * @param pageBean
  207. * @return
  208. */
  209. @RequestMapping(value="/operator_log_list")
  210. public String operatorLogList(Model model,OperaterLog operaterLog,PageBean<OperaterLog> pageBean){
  211. model.addAttribute("pageBean", operaterLogService.findList(operaterLog, pageBean));
  212. model.addAttribute("operator", operaterLog.getOperator());
  213. model.addAttribute("title", "日志列表");
  214. return "admin/system/operator_log_list";
  215. }
  216. /**
  217. * 删除操作日志,可删除多个
  218. * @param ids
  219. * @return
  220. */
  221. @RequestMapping(value="/delete_operator_log",method=RequestMethod.POST)
  222. @ResponseBody
  223. public Result<Boolean> delete(String ids){
  224. if(!StringUtils.isEmpty(ids)){
  225. String[] splitIds = ids.split(",");
  226. for(String id : splitIds){
  227. operaterLogService.delete(Long.valueOf(id));
  228. }
  229. }
  230. return Result.success(true);
  231. }
  232. /**
  233. * 清空整个日志
  234. * @return
  235. */
  236. @RequestMapping(value="/delete_all_operator_log",method=RequestMethod.POST)
  237. @ResponseBody
  238. public Result<Boolean> deleteAll(){
  239. operaterLogService.deleteAll();
  240. return Result.success(true);
  241. }
  242. }

源码获取:博客首页 "资源" 里下载!

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/155650
推荐阅读
相关标签
  

闽ICP备14008679号