• Java项目:SSM酒店客房管理系统


    作者主页:夜未央5788

     简介:Java领域优质创作者、Java项目、学习资料、技术互助

    文末获取源码

     

    项目介绍

    本项目分为前后台,前台为用户角色登录,后台为管理员角色登录。

    管理员角色包含以下功能:

    管理员登录,用户管理,客房类型管理,客房信息管理,预订管理,入住信息管理等功能。

    用户角色包含以下功能:
    用户首页,查看客房,客房预订,查看客房评价,酒店客房评价等功能。

    环境需要

    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/8.0版本均可;
    6.是否Maven项目:是;

    技术栈

    1. 后端:Spring+SpringMVC+Mybatis

    2. 前端:JSP+CSS+JavaScript+jquery+bootstrap

    使用说明

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

    后台管理地址:http://localhost:8080/
    管理员账号/密码:admin/123456

    运行截图

    前台界面-用户角色

     

     

     

     

     

    后台界面-管理员角色

     

     

     

     

     

    相关代码

    CommentController

    1. package cn.edu.glut.jiudian.controller;
    2. import cn.edu.glut.jiudian.entity.Comment;
    3. import cn.edu.glut.jiudian.service.CommentService;
    4. import org.springframework.beans.factory.annotation.Autowired;
    5. import org.springframework.stereotype.Controller;
    6. import org.springframework.web.bind.annotation.RequestMapping;
    7. import org.springframework.web.bind.annotation.RequestParam;
    8. import org.springframework.web.bind.annotation.ResponseBody;
    9. import org.springframework.web.servlet.ModelAndView;
    10. import java.util.HashMap;
    11. import java.util.List;
    12. /**
    13. * @author stone(huangshizhang) at 2019-06-11 15:59
    14. */
    15. @Controller
    16. public class CommentController {
    17. @Autowired
    18. private CommentService commentService;
    19. private List commentList = null;
    20. private List geRoomComment = null;
    21. @RequestMapping("roomCommentList")
    22. @ResponseBody
    23. public Object roomCommentList(@RequestParam("roomId") String roomId){
    24. commentList = commentService.getRoomComment(roomId);
    25. //HashMap> res = new HashMap<>();
    26. //res.put("commentList", commentList);
    27. return "1";
    28. }
    29. @RequestMapping("geRoomComment")
    30. @ResponseBody
    31. public Object geRoomComment(@RequestParam("roomId") String roomId){
    32. geRoomComment = commentService.getRoomComment(roomId);
    33. //HashMap> res = new HashMap<>();
    34. //res.put("commentList", commentList);
    35. return "1";
    36. }
    37. @RequestMapping("comment_management.html")
    38. public ModelAndView commentManagement(){
    39. ModelAndView mav = new ModelAndView("comment_management");
    40. mav.addObject("commentList", geRoomComment);
    41. return mav;
    42. }
    43. @RequestMapping("room_comment.html")
    44. public ModelAndView modalRoomComment(){
    45. ModelAndView mav = new ModelAndView("room_comment");
    46. mav.addObject("commentList", commentList);
    47. return mav;
    48. }
    49. @RequestMapping("addRoomComment")
    50. @ResponseBody
    51. public Object addRoomComment(Comment comment){
    52. comment.setReleaseTime(new java.sql.Date(new java.util.Date().getTime()));
    53. HashMap res = new HashMap<>();
    54. if (commentService.addComment(comment)) {
    55. res.put("stateCode", "1");
    56. } else {
    57. res.put("stateCode", "0");
    58. }
    59. return res;
    60. }
    61. @RequestMapping("write_comment.html")
    62. public ModelAndView writeComment(){
    63. return new ModelAndView("write_comment");
    64. }
    65. @RequestMapping("deleteComment")
    66. @ResponseBody
    67. public Object deleteComment(@RequestParam("serNum") Integer serNum, @RequestParam("roomId") String roomId){
    68. Comment comment = new Comment();
    69. comment.setSerNum(serNum);
    70. comment.setContent("");
    71. HashMap> res = new HashMap<>();
    72. if (commentService.updateByPrimaryKey(comment)) {
    73. List commentList1 = commentService.getRoomComment(roomId);
    74. res.put("commentList", commentList1);
    75. return res;
    76. } else {
    77. return false;
    78. }
    79. }
    80. }

    登录控制器

    1. package cn.edu.glut.jiudian.controller;
    2. import cn.edu.glut.jiudian.entity.Admin;
    3. import cn.edu.glut.jiudian.entity.User;
    4. import cn.edu.glut.jiudian.service.LoginService;
    5. import org.springframework.beans.factory.annotation.Autowired;
    6. import org.springframework.stereotype.Controller;
    7. import org.springframework.web.bind.annotation.RequestMapping;
    8. import org.springframework.web.bind.annotation.RequestMethod;
    9. import org.springframework.web.bind.annotation.ResponseBody;
    10. import org.springframework.web.servlet.ModelAndView;
    11. import javax.servlet.http.HttpServletRequest;
    12. import java.util.HashMap;
    13. /**
    14. * @author stone(huangshizhang) at 2019-06-04 09:37
    15. */
    16. @Controller
    17. public class LoginController {
    18. @Autowired
    19. private LoginService loginService;
    20. @RequestMapping(value = {"/","adminLogin.html"})
    21. public ModelAndView toAdminLogin(HttpServletRequest request) {
    22. request.getSession().invalidate();
    23. return new ModelAndView("index");
    24. }
    25. @RequestMapping("adminLogout.html")
    26. public String adminLogout(HttpServletRequest request) {
    27. request.getSession().invalidate();
    28. return "redirect:adminLogin.html";
    29. }
    30. @RequestMapping(value = {"userLogin.html"})
    31. public ModelAndView toUserLogin(HttpServletRequest request) {
    32. request.getSession().invalidate();
    33. return new ModelAndView("user_main");
    34. }
    35. @RequestMapping("userLogout.html")
    36. public String userLogout(HttpServletRequest request) {
    37. request.getSession().invalidate();
    38. return "redirect:userLogin.html";
    39. }
    40. @RequestMapping(value = "/adminLoginCheck", method = RequestMethod.POST)
    41. @ResponseBody
    42. public Object adminLoginCheck(HttpServletRequest request, Admin admin){
    43. Admin admin1 = loginService.selectAdmin(admin.getAdminName(), admin.getAdminPwd());
    44. HashMap res = new HashMap<>();
    45. if (admin1 != null){
    46. request.getSession().setAttribute("admin", admin1);
    47. res.put("stateCode", "1");
    48. return res;
    49. }else {
    50. res.put("stateCode", "0");
    51. }
    52. return res;
    53. }
    54. @RequestMapping(value = "/userLoginCheck", method = RequestMethod.POST)
    55. @ResponseBody
    56. public Object userLoginCheck(HttpServletRequest request, User user){
    57. User user1 = loginService.selectUser(user.getUserName(), user.getUserPwd());
    58. HashMap res = new HashMap<>();
    59. if (user1 != null){
    60. request.getSession().setAttribute("user", user1);
    61. res.put("stateCode", "1");
    62. return res;
    63. }else {
    64. res.put("stateCode", "0");
    65. }
    66. return res;
    67. }
    68. @RequestMapping("admin_main.html")
    69. public ModelAndView adminMain(){
    70. return new ModelAndView("admin_main");
    71. }
    72. @RequestMapping("userRegister")
    73. @ResponseBody
    74. public Object userRegister(User user){
    75. HashMap res = new HashMap<>();
    76. if (loginService.selectUserByName(user.getUserName()) > 0){
    77. res.put("registerState", "2");
    78. } else {
    79. if (loginService.addUser(user)) {
    80. res.put("registerState", "1");
    81. } else {
    82. res.put("registerState", "0");
    83. }
    84. }
    85. return res;
    86. }
    87. }

    订单控制器

    1. package cn.edu.glut.jiudian.controller;
    2. import cn.edu.glut.jiudian.entity.Order;
    3. import cn.edu.glut.jiudian.entity.Room;
    4. import cn.edu.glut.jiudian.service.OrderService;
    5. import cn.edu.glut.jiudian.service.RoomService;
    6. import org.springframework.beans.factory.annotation.Autowired;
    7. import org.springframework.stereotype.Controller;
    8. import org.springframework.web.bind.annotation.RequestMapping;
    9. import org.springframework.web.bind.annotation.RequestParam;
    10. import org.springframework.web.bind.annotation.ResponseBody;
    11. import org.springframework.web.servlet.ModelAndView;
    12. import java.util.HashMap;
    13. import java.util.List;
    14. /**
    15. * @author stone(huangshizhang) at 2019-06-13 19:55
    16. */
    17. @Controller
    18. public class OrderController {
    19. @Autowired
    20. private OrderService orderService;
    21. @Autowired
    22. private RoomService roomService;
    23. private Order checkout;
    24. @RequestMapping("ruzhu_management.html")
    25. public ModelAndView ruzhuManagement(){
    26. List orderList = orderService.selectAll();
    27. ModelAndView mav = new ModelAndView("ruzhu_management");
    28. mav.addObject("orderList", orderList);
    29. return mav;
    30. }
    31. @RequestMapping("addPayment")
    32. @ResponseBody
    33. public Object addPayment(Order order){
    34. order.setEndTime(new java.sql.Date(new java.util.Date().getTime()));
    35. HashMap res = new HashMap<>();
    36. if (orderService.updateByRoomId(order)) {
    37. res.put("stateCode", "1");
    38. } else {
    39. res.put("stateCode", "0");
    40. }
    41. return res;
    42. }
    43. @RequestMapping("checkout")
    44. @ResponseBody
    45. public Object checkout(@RequestParam("roomId") String roomId){
    46. checkout = orderService.selectByRoomId(roomId);
    47. return true;
    48. }
    49. @RequestMapping("ruzhu_checkout.html")
    50. public ModelAndView ruzhuCheckout(){
    51. ModelAndView mav = new ModelAndView("ruzhu_checkout");
    52. mav.addObject("checkout", checkout);
    53. return mav;
    54. }
    55. @RequestMapping("ruzhu_add.html")
    56. public ModelAndView ruzhuAdd(){
    57. List roomList = roomService.selectNotInRuZhu();
    58. ModelAndView mav = new ModelAndView("ruzhu_add");
    59. mav.addObject("roomList", roomList);
    60. return mav;
    61. }
    62. @RequestMapping("addRuZhu")
    63. @ResponseBody
    64. public Object addRuZhu(Order order){
    65. order.setStartTime(new java.sql.Date(new java.util.Date().getTime()));
    66. HashMap res = new HashMap<>();
    67. if (orderService.addOrder(order)) {
    68. res.put("stateCode", "1");
    69. } else {
    70. res.put("stateCode", "0");
    71. }
    72. return res;
    73. }
    74. @RequestMapping("deleteRuZhu")
    75. @ResponseBody
    76. public Object deleteRuZhu(@RequestParam("roomId") String roomId){
    77. HashMap res = new HashMap<>();
    78. if (orderService.deleteByRoomId(roomId)) {
    79. res.put("stateCode", "1");
    80. } else {
    81. res.put("stateCode", "0");
    82. }
    83. return res;
    84. }
    85. }

    用户控制器

    1. package cn.edu.glut.jiudian.controller;
    2. import cn.edu.glut.jiudian.entity.Notice;
    3. import cn.edu.glut.jiudian.entity.Room;
    4. import cn.edu.glut.jiudian.entity.RoomType;
    5. import cn.edu.glut.jiudian.entity.User;
    6. import cn.edu.glut.jiudian.service.*;
    7. import org.springframework.beans.factory.annotation.Autowired;
    8. import org.springframework.stereotype.Controller;
    9. import org.springframework.web.bind.annotation.RequestMapping;
    10. import org.springframework.web.bind.annotation.RequestMethod;
    11. import org.springframework.web.bind.annotation.RequestParam;
    12. import org.springframework.web.bind.annotation.ResponseBody;
    13. import org.springframework.web.servlet.ModelAndView;
    14. import java.util.HashMap;
    15. import java.util.List;
    16. /**
    17. * @author stone(huangshizhang) at 2019-06-07 20:02
    18. */
    19. @Controller
    20. public class UserController {
    21. @Autowired
    22. private RoomTypeService roomTypeService;
    23. @Autowired
    24. private ReserveService reserveService;
    25. @Autowired
    26. private RoomService roomService;
    27. @Autowired
    28. private NoticeService noticeService;
    29. @Autowired
    30. private UserService userService;
    31. @RequestMapping("user_main.html")
    32. public ModelAndView userMain(){
    33. List roomTypeList = roomTypeService.selectAll();
    34. ModelAndView mav = new ModelAndView("user_main");
    35. mav.addObject("roomTypeList", roomTypeList);
    36. List roomList = roomService.selectAll();
    37. mav.addObject("roomList", roomList);
    38. List noticeList = noticeService.selectAll();
    39. mav.addObject("noticeList", noticeList);
    40. return mav;
    41. }
    42. @RequestMapping(value = "room_type.html", method = RequestMethod.GET)
    43. public ModelAndView roomType(@RequestParam(value = "typeId") int typeId, @RequestParam(value = "type") String type){
    44. List roomList = reserveService.selectByRoomType(type);
    45. ModelAndView mav = new ModelAndView("user_main");
    46. mav.addObject("roomList", roomList);
    47. return mav;
    48. }
    49. @RequestMapping("deleteUser")
    50. @ResponseBody
    51. public Object deleteUser(@RequestParam("userName") String userName){
    52. HashMap res = new HashMap<>();
    53. if (userService.deleteUser(userName)){
    54. res.put("stateCode", "1");
    55. } else {
    56. res.put("stateCode", "0");
    57. }
    58. return res;
    59. }
    60. @RequestMapping("user_management.html")
    61. public ModelAndView toUserInfoManagement(){
    62. List userList = userService.selectAll();
    63. ModelAndView mav = new ModelAndView("user_management");
    64. mav.addObject("userList", userList);
    65. return mav;
    66. }
    67. }

    如果也想学习本系统,下面领取。关注并回复:130ssm

  • 相关阅读:
    MySQL之InnoDB引擎(六)
    详细总结SoC、DSP、MCU、GPU和FPGA等基础概念
    力扣--在排序数组中查找元素的第一个和最后一个位置
    Java实现文件变化监听
    离散数学 --- 命题逻辑 -- 命题符号化与命题公式
    shell脚本查询硬件信息(仅在centos7和rh7做了测试)
    技术分享 | MySQL 存储过程中的只读语句超时怎么办?
    猿创征文|体验新一代分布式数据库—OceanBase
    机器学习1
    4.3 数据库迁移
  • 原文地址:https://blog.csdn.net/hanyunlong1989/article/details/126552028