Java项目:103SSM酒店管理系统

2023-12-31 21:30:22

博主主页:Java旅途
简介:分享计算机知识、学习路线、系统源码及教程
文末获取源码

一、项目介绍

酒店管理系统基于Spring+SpringMVC+Mybatis开发,功能简单,可用于毕设或者课程设计。

管理员功能如下:

  • 房间管理
  • 住客入住
  • 住客管理
  • 会员管理
  • 登录、修改密码
  • 数据导出

二、技术框架

  • 后端:Spring,Springmvc,Mybatis
  • 前端:layui

三、安装教程

  1. 用idea打开项目
  2. 在idea中配置jdk环境
  3. 配置maven环境并下载依赖
  4. 配置tomcat8.0
  5. 新建数据库,导入数据库文件
  6. 在jdbc.properties文件中将数据库账号密码改成自己本地的
  7. 启动运行, 管理员账号密码 admin/123456

四、运行截图

image-20230710150317522

image-20230710150352160

image-20230710150412628

image-20230710150632768

五、相关代码

GuestController

package com.hotel.controller;

import com.hotel.pojo.Guests;
import com.hotel.service.GuestsServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/guests")
public class GuestsController {

    @Autowired
            GuestsServiceImpl guestsService;

    @RequestMapping("/add")
    public ModelAndView add(Guests guests){
        ModelAndView mv = new ModelAndView();
        guestsService.addGuests(guests);
        mv.setViewName("suc_g");
        return mv;
    }

    @RequestMapping("/delete")
    public String delete(int id){
        guestsService.deleteGuestsById(id);
        return "redirect:/guests/list";
    }

    @RequestMapping("/list")
    public ModelAndView list(){
        ModelAndView mv = new ModelAndView();
        List<Guests> guestsList=guestsService.queryAllGuests();
        mv.addObject("list",guestsList);
        mv.setViewName("guests_list");
        return mv;
    }

    @RequestMapping("/update1")
    public ModelAndView update1(int id){
        ModelAndView mv = new ModelAndView();
        Guests guests = guestsService.queryGuestsById(id);
        mv.addObject("g",guests);
        mv.setViewName("guests_update");
        return mv;
    }

    @RequestMapping("/update2")
    public String update2(Guests g ){
        guestsService.updateGuestsById(g);
        return ("redirect:/guests/list");
    }

    @RequestMapping("/find")
    public ModelAndView find(String findByPhone){
        ModelAndView mv = new ModelAndView();
        Guests guests = guestsService.queryGuestsByPhone(findByPhone);
        List<Guests> guestsList=new ArrayList<Guests>();
        guestsList.add(guests);
        if (guests==null){
            guestsList=guestsService.queryAllGuests();
           mv.addObject("error","未查询出结果");
        }
        mv.addObject("list",guestsList);
        mv.setViewName("guests_list");
        return mv;
    }
}

HomeController

package com.hotel.controller;

import com.hotel.pojo.Home;
import com.hotel.service.HomeServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@Controller
@RequestMapping("/home")

public class HomeController {

    @Autowired
            HomeServiceImpl homeService;

    @RequestMapping("/add")
    public String add(Home home, Model model) throws IOException{

        String sqlPath = null;
        //定义文件保存的本地路径
        String localPath="F:\\bysj2\\项目整理\\付费毕设\\103SSM的酒店管理系统\\源码\\Hotel_Manage\\src\\main\\webapp\\upload\\";
        //定义 文件名
        String filename=null;
        if(!home.getFile().isEmpty()){
            //生成uuid作为文件名称
            String uuid = UUID.randomUUID().toString().replaceAll("-","");
            //获得文件类型(可以判断如果不是图片,禁止上传)
            String contentType=home.getFile().getContentType();
            //获得文件后缀名
            String suffixName=contentType.substring(contentType.indexOf("/")+1);
            //得到 文件名
            filename=uuid+"."+suffixName;
            System.out.println(filename);
            //文件保存路径
            home.getFile().transferTo(new File(localPath+filename));
        }
        //把图片的相对路径保存至数据库
        sqlPath = "/upload/"+filename;
        System.out.println(sqlPath);
        home.setImg(sqlPath);

        homeService.addHome(home);
        model.addAttribute("home",home);
        return "home_show";
    }

    @RequestMapping("/delete")
    public String delete(Integer  id){
        homeService.deleteHomeById(id);
        return "redirect:/home/list";
    }

    @RequestMapping("/list")
    public ModelAndView list(){
        ModelAndView mv = new ModelAndView();
        List<Home> homeList=homeService.queryAllHome();
        mv.addObject("list",homeList);
        mv.setViewName("home_list");
        return mv;
    }

    @RequestMapping("/update1")
    public ModelAndView update1(Integer  id){
        ModelAndView mv = new ModelAndView();
        Home home = homeService.queryHomeById(id);
        mv.addObject("h",home);
        mv.setViewName("home_update");
        return mv;
    }

    @RequestMapping("/update2")
    public String update2(Home h)throws IOException{
        String sqlPath = null;
        //定义文件保存的本地路径
        String localPath="F:\\bysj2\\项目整理\\付费毕设\\103SSM的酒店管理系统\\源码\\Hotel_Manage\\src\\main\\webapp\\upload\\";
        //定义 文件名
        String filename=null;
        if(!h.getFile().isEmpty()){
            //生成uuid作为文件名称
            String uuid = UUID.randomUUID().toString().replaceAll("-","");
            //获得文件类型(可以判断如果不是图片,禁止上传)
            String contentType=h.getFile().getContentType();
            //获得文件后缀名
            String suffixName=contentType.substring(contentType.indexOf("/")+1);
            //得到 文件名
            filename=uuid+"."+suffixName;
            System.out.println(filename);
            //文件保存路径
            h.getFile().transferTo(new File(localPath+filename));
        }
        //把图片的相对路径保存至数据库
        sqlPath = "/upload/"+filename;
        System.out.println(sqlPath);
        h.setImg(sqlPath);

        homeService.updateHomeById(h);
        return ("redirect:/home/list");
    }

    @RequestMapping("/show")
    public ModelAndView show(Integer  id){
        ModelAndView mv = new ModelAndView();
        Home home=homeService.queryHomeById(id);
        mv.addObject("home",home);
        mv.setViewName("home_show");
        return mv;
    }

    @RequestMapping("/find")
    public ModelAndView find(int findByNum ){
        ModelAndView mv = new ModelAndView();
        Home home = homeService.queryHomeByNum(findByNum);
        List<Home> homeList=new ArrayList<Home>();
        homeList.add(home);
        if (home==null){
            homeList=homeService.queryAllHome();
            mv.addObject("error","未查询出结果");
        }
        mv.addObject("list",homeList);
        mv.setViewName("home_list");
        return mv;
    }

    @RequestMapping("/type1")
    public String type1(Integer id,Model model){
        Home home = homeService.queryHomeById(id);
        model.addAttribute("h",home);
        return "H_Type_update";
    }

    @RequestMapping("/type2")
    public String type2(Home home){
        homeService.updateH_TypeById(home);
        return "redirect:/home/list";
    }
}

大家点赞、收藏、关注、评论啦 、👇🏻点开下方卡片👇🏻关注后回复 100

文章来源:https://blog.csdn.net/m0_37968982/article/details/135319283
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。