作者主页:夜未央5788
简介:Java领域优质创作者、Java项目、学习资料、技术互助
文末获取源码
酒店管理系统-温情小筑后台管理系统
系统概要
项目主要功能包括:
住客管理:住客入住、住客列表;
房间管理:房间列表、添加房间、修改房间状态;
会员管理:新增会员、会员列表;
系统设置:网站信息、修改密码、清除缓存;
数据表:生成Excel并导出等功能,适合java新手学习;
由于本程序规模不大,可供课程设计,毕业设计学习演示之用
更多项目源码,请到“源码空间站”,地址:http://www.shuyue.fun/
技术选型
1.后台技术选型:SSM(Spring SpringMVC Mybatis)
2.前端技术选型:LayUI
开发环境
1.编程语言:Java
2.开发工具:IDEA/Eclipse、Navicat
3.项目构建:Maven 3.5.2
4.服务器:Tomcat 8.0及以上
5.数据库:MySQL5.7
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 将项目中jdbc.properties配置文件中的数据库配置改为自己的配置;
3. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,配置tomcat,然后运行;
4. 运行项目,输入localhost:8080/ 登录
运行
导入项目并运行成功后,在tomcat路径中设置为/,注意路径中不要带有项目名,否则会导致项目运行异常;
运行截图
相关代码
AdminController
package com.hotel.controller;
import com.hotel.pojo.Admin;
import com.hotel.service.AdminServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/admin")
public class AdminController {
@Autowired
AdminServiceImpl adminService;
@RequestMapping("/login")
public String login(String username, int password){
Admin admin=adminService.findAdmin(username,password );
if(admin!=null){
if(admin.getPassword()==password){
return "index";
}else {
return "error";
}
}
return "error";
}
@RequestMapping("/updatePwd")
public String update(Admin admin){
adminService.updatePwd(admin);
System.out.println(admin);
return "suc_a";
}
}
ExcelController
package com.hotel.controller;
import com.hotel.pojo.Home;
import com.hotel.pojo.Vip;
import com.hotel.service.HomeServiceImpl;
import com.hotel.service.VipServiceImpl;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
@Controller
@RequestMapping("/excel")
public class ExcelController {
@Autowired
HomeServiceImpl homeService;
@Autowired
VipServiceImpl vipService;
@RequestMapping("/home")
public void excel_home(HttpServletResponse response )throws IOException {
response.setCharacterEncoding("UTF-8");
List<Home> homeList=homeService.queryAllHome();
//创建excel文件
HSSFWorkbook wb = new HSSFWorkbook();
//创建sheet页
HSSFSheet sheet = wb.createSheet("房间信息");
//创建标题行
HSSFRow titleRow = sheet.createRow(0);
titleRow.createCell(0).setCellValue("编号");
titleRow.createCell(1).setCellValue("房间号");
titleRow.createCell(2).setCellValue("房间类型");
titleRow.createCell(3).setCellValue("价格");
titleRow.createCell(4).setCellValue("状态");
titleRow.createCell(5).setCellValue("描述");
//获取需要下载表对应的pojo类
for(Home home:homeList){
HSSFRow dataRow = sheet.createRow(sheet.getLastRowNum()+1);
dataRow.createCell(0).setCellValue(home.getId());
dataRow.createCell(1).setCellValue(home.getNum());
dataRow.createCell(2).setCellValue(home.getH_Type());
dataRow.createCell(3).setCellValue(home.getPrice());
dataRow.createCell(4).setCellValue(home.getState());
dataRow.createCell(5).setCellValue(home.getText());
}
// 设置下载时客户端Excel的名称
response.setContentType("application/octet-stream;charset=utf-8");
response.setHeader("Content-Disposition", "attachment;filename="
+ new String("房间信息表".getBytes(),"iso-8859-1") + ".xls");
OutputStream ouputStream = response.getOutputStream();
wb.write(ouputStream);
ouputStream.flush();
ouputStream.close();
}
@RequestMapping("/vip")
public void excel_vip(HttpServletResponse response )throws IOException {
response.setCharacterEncoding("UTF-8");
List<Vip> vipList=vipService.queryAllVip();
//创建excel文件
HSSFWorkbook wb = new HSSFWorkbook();
//创建sheet页
HSSFSheet sheet = wb.createSheet("会员信息");
//创建标题行
HSSFRow titleRow = sheet.createRow(0);
titleRow.createCell(0).setCellValue("编号");
titleRow.createCell(1).setCellValue("姓名");
titleRow.createCell(2).setCellValue("性别");
titleRow.createCell(3).setCellValue("身份证号");
titleRow.createCell(4).setCellValue("手机号");
titleRow.createCell(5).setCellValue("会员类型");
titleRow.createCell(6).setCellValue("开通时间");
titleRow.createCell(7).setCellValue("到期时间");
for(Vip vip:vipList){
HSSFRow dataRow = sheet.createRow(sheet.getLastRowNum()+1);
dataRow.createCell(0).setCellValue(vip.getId());
dataRow.createCell(1).setCellValue(vip.getName());
dataRow.createCell(2).setCellValue(vip.getSex());
dataRow.createCell(3).setCellValue(vip.getCard());
dataRow.createCell(4).setCellValue(vip.getPhone());
dataRow.createCell(5).setCellValue(vip.getV_Type());
dataRow.createCell(6).setCellValue(vip.getStartTime());
dataRow.createCell(7).setCellValue(vip.getEndTime());
}
// 设置下载时客户端Excel的名称
response.setContentType("application/octet-stream;charset=utf-8");
response.setHeader("Content-Disposition", "attachment;filename="
+ new String("客户会员名单".getBytes(),"iso-8859-1") + ".xls");
OutputStream ouputStream = response.getOutputStream();
wb.write(ouputStream);
ouputStream.flush();
ouputStream.close();
}
}
GuestsController
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="/DownLoad/";
String localPath="/Users/admin/Desktop/log/";
//定义 文件名
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="/Download/";
String localPath="/Users/admin/Desktop/log/";
//定义 文件名
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";
}
}
如果也想学习本系统,下面领取。关注并回复:011ssm
本文含有隐藏内容,请 开通VIP 后查看