作者主页:夜未央5788
简介:Java领域优质创作者、Java项目、学习资料、技术互助
文末获取源码
项目介绍
一套完整的民宿短租(之前给别人做成该类)或者是酒店预订入住信息管理系统,系统分为前台会员和后台管理员,系统设计满足了前台会员的注册登陆,民宿首页展示,名宿客房展示,名宿客房预订,民宿商品展示,以及联系留言等。系统设计后台管理员对系统用户管理,预订、入住、换房、结账管理。客房的新增修改,商品的新增修改等,以及PublicArea(公共区域)管理等。功能全面,逻辑清晰,值得下载学习哦。
本项目分为前台和后台两个项目,前台与后台需要分别单独运行,前台为普通用户登录,后台为普通用户登录;
由于本程序规模不大,可供课程设计,毕业设计学习演示之用
环境需要
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版本;
6.是否Maven项目:否;
技术栈
1. 后端:Spring+Struts+Hibernate
2. 前端:JSP+CSS+JavaScript
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中jdbc.properties配置文件中的数据库配置改为自己的配置;
4. 运行项目,后台地址http://localhost:8080/manage_index.do 登录 注:tomcat中路径设置为/
管理员用户:admin 密码:admin
前台地址:http://localhost:8083/login_index.do 登录 注:tomcat中路径设置为/
用户:zhangsan 密码:123
运行截图
相关代码
BookAction
package com.hotel.action;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.hotel.model.Book;
import com.hotel.model.Item;
import com.hotel.model.Item_cat;
import com.hotel.model.Room;
import com.hotel.model.Room_cat;
import com.hotel.model.User;
import com.hotel.model.UserItem;
import com.hotel.model.UserRoom;
import com.hotel.service.BookService;
import com.hotel.service.ItemCatService;
import com.hotel.service.ItemService;
import com.hotel.service.LogService;
import com.hotel.service.RoomCatService;
import com.hotel.service.RoomService;
import com.hotel.service.UserRoomService;
import com.hotel.service.UserService;
import com.hotel.service.UserItemService;
import com.hotel.utils.Pager;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
@Controller("bookAction")
@Scope("prototype")
public class BookAction extends ActionSupport implements ModelDriven<Book>{
private Book book;
private Room room;
public Room getRoom() {
return room;
}
public void setRoom(Room room) {
this.room = room;
}
private int userId;
private int bookId;
private int roomId;
private int itemId;
public int getRoomId() {
return roomId;
}
public void setRoomId(int roomId) {
this.roomId = roomId;
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public int getBookId() {
return bookId;
}
public void setBookId(int bookId) {
this.bookId = bookId;
}
public int getItemId() {
return itemId;
}
public void setItemId(int itemId) {
this.itemId = itemId;
}
@Override
public Book getModel() {
if(book==null) book = new Book();
return book;
}
@Autowired
private LogService logService;
@Autowired
private RoomService roomService;
@Autowired
private RoomCatService roomCatService;
@Autowired
private BookService bookService;
@Autowired
private UserService userService;
@Autowired
private ItemService itemSerivce;
@Autowired
private ItemCatService itemCatService;
@Autowired
private UserItemService userItemService;
@Autowired
private UserRoomService userRoomService;
/**
* 获取用户预订房间信息列表
* @return
*/
public String bookList(){
Pager<Book> pagers = bookService.listAll();
ActionContext.getContext().put("pagers", pagers);
return SUCCESS;
}
/**
* 获取取消预定信息详情
* @Description (TODO这里用一句话描述这个方法的作用)
* @return
*/
public String updateBook(){
Book book =bookService.bookDetail(bookId);
ActionContext.getContext().put("book", book);
return "success";
}
/**
* 后台管理员取消预定
* @Description (TODO这里用一句话描述这个方法的作用)
* @return
*/
public String cancelBook(){
Book book =bookService.bookDetail(bookId);
//删除订单表
bookService.delBook(bookId);
//修改房间状态
Room room=roomService.roomDetail(book.getRoom().getId());
room.setIsLive(1);
roomService.update(room);
//修改房间类别数量
Room_cat room_cat=roomCatService.load(room.getRoom_cat().getId());
room_cat.setNum(room_cat.getNum()+1);
roomCatService.update(room_cat);
String content="取消预定";
HttpSession session =ServletActionContext.getRequest().getSession();
int userId = Integer.parseInt( session.getAttribute("userId").toString());
//插入日志
logService.addLog(content,userId);
ActionContext.getContext().put("url", "/book_bookList.do");
return "redirect";
}
/**
* 获取用户已入住信息列表
* @return
*/
public String liveList(){
Pager<Book> pagers = bookService.listAll();
ActionContext.getContext().put("pagers", pagers);
return SUCCESS;
}
/**
* 获取入住详情信息列表
* @Description (TODO这里用一句话描述这个方法的作用)
* @return
*/
public String liveRoom(){
Book book =bookService.bookDetail(bookId);
ActionContext.getContext().put("book", book);
return "success";
}
/**
* 后台管理员立即入住
* @Description (TODO这里用一句话描述这个方法的作用)
* @return
*/
public String live(){
Book book =bookService.bookDetail(bookId);
book.setStatus(2);
//更新预定表
bookService.updateBook(book);
//修改房间状态
Room room=roomService.roomDetail(book.getRoom().getId());
room.setIsLive(3);
roomService.update(room);
String content="办理入住";
HttpSession session =ServletActionContext.getRequest().getSession();
int userId = Integer.parseInt( session.getAttribute("userId").toString());
//插入日志
logService.addLog(content,userId);
ActionContext.getContext().put("url", "/book_bookList.do");
return "redirect";
}
/**
* 获取更换房间信息列表
* @return
*/
public String changeRoomList(){
Pager<Book> pagers = bookService.listAllLive();
ActionContext.getContext().put("pagers", pagers);
return SUCCESS;
}
/**
* 获取更换房间信息详情
* @return
*/
public String changeRoom(){
Book book =bookService.bookDetail(bookId);
ActionContext.getContext().put("book", book);
return SUCCESS;
}
/**
* 获取更换房间信息修改页面
* @return
*/
public String roomChange(){
Book book =bookService.bookDetail(bookId);
List<Room_cat> roomCatList=roomCatService.list();
ActionContext.getContext().put("roomCatList", roomCatList);
ActionContext.getContext().put("book", book);
return SUCCESS;
}
/**
* 后台管理员更换房间
* @Description (TODO这里用一句话描述这个方法的作用)
* @return
*/
public String change(){
Book book =bookService.bookDetail(bookId);
book.setStatus(2);
//更新预定表
bookService.updateBook(book);
//修改房间状态
Room room=roomService.roomDetail(book.getRoom().getId());
room.setIsLive(3);
roomService.update(room);
String content="办理入住";
HttpSession session =ServletActionContext.getRequest().getSession();
int userId = Integer.parseInt( session.getAttribute("userId").toString());
//插入日志
logService.addLog(content,userId);
ActionContext.getContext().put("url", "/book_bookList.do");
return "redirect";
}
/**
* 前台预定房间
* @return
*/
public String bookRoom(){
HttpSession session =ServletActionContext.getRequest().getSession();
int userId=0;
if(session.getAttribute("userId")!=null){
userId = Integer.parseInt( session.getAttribute("userId").toString());
}else{
return "login";
}
//更改房间状态变为预定
Room room =roomService.load(roomId);
room.setIsLive(2);
roomService.update(room);
//修改房间类别数量减一
Room_cat room_cat=roomCatService.load(room.getRoom_cat().getId());
room_cat.setNum(room_cat.getNum()-1);
roomCatService.update(room_cat);
//插入订单表
Book book1=new Book();
book1.setBookTime(new Date());
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
String reachTime=sdf.format(book.getReachTime());
String leaveTime=sdf.format(book.getLeaveTime());
Calendar calendar2 = Calendar.getInstance();
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd");
calendar2.add(Calendar.DATE, 3);
String three_days_after = sdf2.format(calendar2.getTime());
int reachTimes = Integer(reachTime);
int three_days_afters =Integer(three_days_after);
if(three_days_afters>reachTimes){
System.out.println("入住时间在当前时间三天之内");
}else if(three_days_afters < reachTimes){
System.out.println("入住时间在当前时间三天之外");
}
Date rTime=new Date();
Date lTime=new Date();
try {
rTime=sdf.parse(reachTime);
lTime=sdf.parse(leaveTime);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
book1.setLeaveTime(lTime);
book1.setReachTime(rTime);
book1.setStatus(1);
book1.setRoomNumber(1);
User user=userService.load(userId);
book1.setBookUser(user);
book1.setRoom(room);
bookService.add(book1);
//插入房间和人关联的表
UserRoom userRoom=new UserRoom();
userRoom.setRoom(room);
userRoom.setUser(user);
userRoomService.add(userRoom);
ActionContext.getContext().put("url", "/login_index.do");
return "redirect";
}
private int Integer(String leaveTime) {
// TODO Auto-generated method stub
return 0;
}
/**
* 前台购买商品
* @return
*/
public String bookItem(){
HttpSession session =ServletActionContext.getRequest().getSession();
int userId=0;
if(session.getAttribute("userId")!=null){
userId = Integer.parseInt( session.getAttribute("userId").toString());
}else{
return "login";
}
Item item =itemSerivce.load(itemId);
//修改商品类别数量减一
Item_cat item_cat=itemCatService.load(item.getItem_cat().getCid());
item_cat.setNum(item_cat.getNum()-1);
itemCatService.update(item_cat);
User user=userService.load(userId);
//插入商品和人关联的表
UserItem userItem =new UserItem();
userItem.setItem(item);
userItem.setUser(user);
userItemService.add(userItem);
ActionContext.getContext().put("url", "/login_index.do");
return "redirect";
}
}
ItemAction
package com.hotel.action;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.hotel.model.Item;
import com.hotel.model.Item_cat;
import com.hotel.model.Room;
import com.hotel.service.ItemCatService;
import com.hotel.service.ItemService;
import com.hotel.service.LogService;
import com.hotel.utils.Pager;
import com.hotel.utils.UUIDUtils;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
@Controller("itemAction")
@Scope("prototype")
public class ItemAction extends ActionSupport implements ModelDriven<Item>{
private Item item;
private int itemId;
private int itemCatId;
public int getItemCatId() {
return itemCatId;
}
public void setItemCatId(int itemCatId) {
this.itemCatId = itemCatId;
}
public int getItemId() {
return itemId;
}
public void setItemId(int itemId) {
this.itemId = itemId;
}
@Override
public Item getModel() {
if(item==null) item = new Item();
return item;
}
@Autowired
private ItemCatService itemCatService;
@Autowired
private ItemService itemService;
@Autowired
private LogService logService;
//========================图片上传
private File file;
//提交过来的file的名字
private String fileFileName;
//提交过来的file的MIME类型
private String fileContentType;
public File getFile() {
return file;
}
public void setFile(File file) {
this.file = file;
}
public String getFileFileName() {
return fileFileName;
}
public void setFileFileName(String fileFileName) {
this.fileFileName = fileFileName;
}
public String getFileContentType() {
return fileContentType;
}
public void setFileContentType(String fileContentType) {
this.fileContentType = fileContentType;
}
//========================图片上传
/**
* 获取商品信息列表
* @return
* @throws InvocationTargetException
* @throws IllegalAccessException
*/
public String itemList() {
Pager<Item> pagers = itemService.listAll();
ActionContext.getContext().put("pagers", pagers);
return SUCCESS;
}
/**
* 初始化商品新增页面
* @return
*/
public String addItem(){
List<Item_cat> itemCatList=itemCatService.list();
ActionContext.getContext().put("itemCatList", itemCatList);
return SUCCESS;
}
/**
* 新增商品
* @return
*/
public String itemAdd()throws Exception{
//图片上传
String root = "D:/my/upload";
InputStream is = new FileInputStream(file);
fileFileName = UUIDUtils.create()+fileFileName;
OutputStream os = new FileOutputStream(new File(root, fileFileName));
System.out.println("fileFileName: " + fileFileName);
System.out.println("file: " + file.getName());
System.out.println("file: " + file.getPath());
byte[] buffer = new byte[500];
int length = 0;
while(-1 != (length = is.read(buffer, 0, buffer.length)))
{
os.write(buffer);
}
os.close();
is.close();
item.setImage("\\upload\\"+fileFileName);
itemService.add(item);
Item_cat item_cat=itemCatService.load(item.getItem_cat().getCid());
item_cat.setNum(item_cat.getNum()+1);
itemCatService.update(item_cat);
String content="新增商品";
HttpSession session =ServletActionContext.getRequest().getSession();
int userId = Integer.parseInt( session.getAttribute("userId").toString());
//插入日志
logService.addLog(content,userId);
ActionContext.getContext().put("url", "/item_itemList.do");
return "redirect";
}
/**
* 删除商品
* @return
*/
public String delItem(){
Item item =itemService.itemDetail(itemId);
itemService.delItem(itemId);
Item_cat item_cat=itemCatService.load(item.getItem_cat().getCid());
item_cat.setNum(item_cat.getNum()-1);
itemCatService.update(item_cat);
String content="删除商品";
HttpSession session =ServletActionContext.getRequest().getSession();
int userId = Integer.parseInt( session.getAttribute("userId").toString());
//插入日志
logService.addLog(content,userId);
ActionContext.getContext().put("url", "/item_itemList.do");
return "redirect";
}
/**
* 初始化修改页面
* @Description (TODO这里用一句话描述这个方法的作用)
* @return
*/
public String updateItem(){
Item item =itemService.itemDetail(itemId);
List<Item_cat> itemCatList=itemCatService.list();
ActionContext.getContext().put("itemCatList", itemCatList);
ActionContext.getContext().put("item", item);
return "success";
}
/**
* 修改商品
* @return
*/
public String itemUpdate()throws Exception{
if(file!=null){
//图片上传
String root = "D:/my/upload";
InputStream is = new FileInputStream(file);
fileFileName = UUIDUtils.create()+fileFileName;
OutputStream os = new FileOutputStream(new File(root, fileFileName));
System.out.println("fileFileName: " + fileFileName);
System.out.println("file: " + file.getName());
System.out.println("file: " + file.getPath());
byte[] buffer = new byte[500];
int length = 0;
while(-1 != (length = is.read(buffer, 0, buffer.length)))
{
os.write(buffer);
}
os.close();
is.close();
item.setImage("\\upload\\"+fileFileName);
}else{
Item i =itemService.itemDetail(item.getId());
item.setImage(i.getImage());
}
itemService.update(item);
String content="修改商品";
HttpSession session =ServletActionContext.getRequest().getSession();
int userId = Integer.parseInt( session.getAttribute("userId").toString());
//插入日志
logService.addLog(content,userId);
ActionContext.getContext().put("url", "/item_itemList.do");
return "redirect";
}
//前端页面点击商品的页面
public String itemIndex(){
Pager<Item> pagers = itemService.queryItems(itemCatId);
ActionContext.getContext().put("pagers", pagers);
return SUCCESS;
}
}
如果也想学习本系统,下面领取。关注并回复:020ssh