(免费分享)基于jsp,ssm酒店管理系统
创始人
2024-04-22 10:20:56
0

开发工具:eclipse,mysql5.7

Tomcat8.0,jdk1.8

系统分用户前台和管理后台两部分
在这里插入图片描述
前台截图:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

后台截图:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

package com.mypower.controller;import java.beans.PropertyEditorSupport;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;import com.mypower.utils.UserException;public class BaseController {@InitBinder// 必须有一个参数WebDataBinderpublic void initBinder(WebDataBinder binder) {//System.out.println(binder.getFieldDefaultPrefix());binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), false));binder.registerCustomEditor(Integer.class, new PropertyEditorSupport() {@Overridepublic String getAsText() { return (getValue() == null) ? "" : getValue().toString();} @Overridepublic void setAsText(String text) {Integer value = null;if (null != text && !text.equals("")) {  try {value = Integer.valueOf(text);} catch(Exception ex)  { throw new UserException("数据格式输入不正确!"); }  }setValue(value);} });//binder.registerCustomEditor(Integer.class, null,new CustomNumberEditor(Integer.class, null, true));binder.registerCustomEditor(Float.class, new PropertyEditorSupport() {@Overridepublic String getAsText() { return (getValue() == null)? "" : getValue().toString();} @Overridepublic void setAsText(String text)  {Float value = null;if (null != text && !text.equals("")) {try {value = Float.valueOf(text);} catch (Exception e) { throw new UserException("数据格式输入不正确!"); }}setValue(value);}});}/** * 处理图片文件上传,返回保存的文件名路径* fileKeyName: 图片上传表单key* @throws IOException * @throws IllegalStateException */ public String handlePhotoUpload(HttpServletRequest request,String fileKeyName) throws IllegalStateException, IOException {String fileName = "upload/NoImage.jpg";MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; /**构建图片保存的目录**/    String photoBookPathDir = "/upload";     /**得到图片保存目录的真实路径**/    String photoBookRealPathDir = request.getSession().getServletContext().getRealPath(photoBookPathDir);     /**根据真实路径创建目录**/    File photoBookSaveFile = new File(photoBookRealPathDir);     if(!photoBookSaveFile.exists())     photoBookSaveFile.mkdirs();           /**页面控件的文件流**/    MultipartFile multipartFile_photoBook = multipartRequest.getFile(fileKeyName);    if(!multipartFile_photoBook.isEmpty()) {/**获取文件的后缀**/    String suffix = multipartFile_photoBook.getOriginalFilename().substring  (multipartFile_photoBook.getOriginalFilename().lastIndexOf("."));  String smallSuffix = suffix.toLowerCase();if(!smallSuffix.equals(".jpg") && !smallSuffix.equals(".gif") && !smallSuffix.equals(".png") )throw new UserException("图片格式不正确!");/**使用UUID生成文件名称**/    String photoBookFileName = UUID.randomUUID().toString()+ suffix;//构建文件名称     //String logImageName = multipartFile.getOriginalFilename();  /**拼成完整的文件保存路径加文件**/    String photoBookFilePath = photoBookRealPathDir + File.separator  + photoBookFileName;                File photoBookFile = new File(photoBookFilePath);          multipartFile_photoBook.transferTo(photoBookFile);     fileName = "upload/" + photoBookFileName;} return fileName;}/** * 处理图片文件上传,返回保存的文件名路径* fileKeyName: 图片上传表单key* @throws IOException * @throws IllegalStateException */ public String handleFileUpload(HttpServletRequest request,String fileKeyName) throws IllegalStateException, IOException {String fileName = "";MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; /**构建图片保存的目录**/    String photoBookPathDir = "/upload";     /**得到图片保存目录的真实路径**/    String photoBookRealPathDir = request.getSession().getServletContext().getRealPath(photoBookPathDir);     /**根据真实路径创建目录**/    File photoBookSaveFile = new File(photoBookRealPathDir);     if(!photoBookSaveFile.exists())     photoBookSaveFile.mkdirs();           /**页面控件的文件流**/    MultipartFile multipartFile_photoBook = multipartRequest.getFile(fileKeyName);    if(!multipartFile_photoBook.isEmpty()) {/**获取文件的后缀**/    String suffix = multipartFile_photoBook.getOriginalFilename().substring  (multipartFile_photoBook.getOriginalFilename().lastIndexOf("."));/**使用UUID生成文件名称**/    String photoBookFileName = UUID.randomUUID().toString()+ suffix;//构建文件名称     //String logImageName = multipartFile.getOriginalFilename();  /**拼成完整的文件保存路径加文件**/    String photoBookFilePath = photoBookRealPathDir + File.separator  + photoBookFileName;                File photoBookFile = new File(photoBookFilePath);          multipartFile_photoBook.transferTo(photoBookFile);     fileName = "upload/" + photoBookFileName;} return fileName;}/*向客户端输出操作成功或失败信息*/public void writeJsonResponse(HttpServletResponse response,boolean success,String message)throws IOException, JSONException { response.setContentType("text/json;charset=UTF-8");PrintWriter out = response.getWriter(); //将要被返回到客户端的对象 JSONObject json=new JSONObject();json.accumulate("success", success);json.accumulate("message", message);out.println(json.toString());out.flush(); out.close();}}

package com.mypower.controller;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.mypower.po.Notice;
import com.mypower.service.NoticeService;
import com.mypower.utils.ExportExcelUtil;
import com.mypower.utils.UserException;

//Notice管理控制层
@Controller
@RequestMapping(“/Notice”)
public class NoticeController extends BaseController {

/*业务层对象*/
@Resource NoticeService noticeService;@InitBinder("notice")
public void initBinderNotice(WebDataBinder binder) {binder.setFieldDefaultPrefix("notice.");
}
/*跳转到添加Notice视图*/
@RequestMapping(value = "/add", method = RequestMethod.GET)
public String add(Model model,HttpServletRequest request) throws Exception {model.addAttribute(new Notice());return "Notice_add";
}/*客户端ajax方式提交添加新闻公告信息*/
@RequestMapping(value = "/add", method = RequestMethod.POST)
public void add(@Validated Notice notice, BindingResult br,Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {String message = "";boolean success = false;if (br.hasErrors()) {message = "输入信息不符合要求!";writeJsonResponse(response, success, message);return ;}noticeService.addNotice(notice);message = "新闻公告添加成功!";success = true;writeJsonResponse(response, success, message);
}
/*ajax方式按照查询条件分页查询新闻公告信息*/
@RequestMapping(value = { "/list" }, method = {RequestMethod.GET,RequestMethod.POST})
public void list(String title,String publishDate,Integer page,Integer rows, Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {if (page==null || page == 0) page = 1;if (title == null) title = "";if (publishDate == null) publishDate = "";if(rows != 0)noticeService.setRows(rows);List noticeList = noticeService.queryNotice(title, publishDate, page);/*计算总的页数和总的记录数*/noticeService.queryTotalPageAndRecordNumber(title, publishDate);/*获取到总的页码数目*/int totalPage = noticeService.getTotalPage();/*当前查询条件下总记录数*/int recordNumber = noticeService.getRecordNumber();response.setContentType("text/json;charset=UTF-8");PrintWriter out = response.getWriter();//将要被返回到客户端的对象JSONObject jsonObj=new JSONObject();jsonObj.accumulate("total", recordNumber);JSONArray jsonArray = new JSONArray();for(Notice notice:noticeList) {JSONObject jsonNotice = notice.getJsonObject();jsonArray.put(jsonNotice);}jsonObj.accumulate("rows", jsonArray);out.println(jsonObj.toString());out.flush();out.close();
}/*ajax方式按照查询条件分页查询新闻公告信息*/
@RequestMapping(value = { "/listAll" }, method = {RequestMethod.GET,RequestMethod.POST})
public void listAll(HttpServletResponse response) throws Exception {List noticeList = noticeService.queryAllNotice();response.setContentType("text/json;charset=UTF-8"); PrintWriter out = response.getWriter();JSONArray jsonArray = new JSONArray();for(Notice notice:noticeList) {JSONObject jsonNotice = new JSONObject();jsonNotice.accumulate("noticeId", notice.getNoticeId());jsonNotice.accumulate("title", notice.getTitle());jsonArray.put(jsonNotice);}out.println(jsonArray.toString());out.flush();out.close();
}/*前台按照查询条件分页查询新闻公告信息*/
@RequestMapping(value = { "/frontlist" }, method = {RequestMethod.GET,RequestMethod.POST})
public String frontlist(String title,String publishDate,Integer currentPage, Model model, HttpServletRequest request) throws Exception  {if (currentPage==null || currentPage == 0) currentPage = 1;if (title == null) title = "";if (publishDate == null) publishDate = "";List noticeList = noticeService.queryNotice(title, publishDate, currentPage);/*计算总的页数和总的记录数*/noticeService.queryTotalPageAndRecordNumber(title, publishDate);/*获取到总的页码数目*/int totalPage = noticeService.getTotalPage();/*当前查询条件下总记录数*/int recordNumber = noticeService.getRecordNumber();request.setAttribute("noticeList",  noticeList);request.setAttribute("totalPage", totalPage);request.setAttribute("recordNumber", recordNumber);request.setAttribute("currentPage", currentPage);request.setAttribute("title", title);request.setAttribute("publishDate", publishDate);return "Notice/notice_frontquery_result"; 
}/*前台查询Notice信息*/
@RequestMapping(value="/{noticeId}/frontshow",method=RequestMethod.GET)
public String frontshow(@PathVariable Integer noticeId,Model model,HttpServletRequest request) throws Exception {/*根据主键noticeId获取Notice对象*/Notice notice = noticeService.getNotice(noticeId);request.setAttribute("notice",  notice);return "Notice/notice_frontshow";
}/*ajax方式显示新闻公告修改jsp视图页*/
@RequestMapping(value="/{noticeId}/update",method=RequestMethod.GET)
public void update(@PathVariable Integer noticeId,Model model,HttpServletRequest request,HttpServletResponse response) throws Exception {/*根据主键noticeId获取Notice对象*/Notice notice = noticeService.getNotice(noticeId);response.setContentType("text/json;charset=UTF-8");PrintWriter out = response.getWriter();//将要被返回到客户端的对象 JSONObject jsonNotice = notice.getJsonObject();out.println(jsonNotice.toString());out.flush();out.close();
}/*ajax方式更新新闻公告信息*/
@RequestMapping(value = "/{noticeId}/update", method = RequestMethod.POST)
public void update(@Validated Notice notice, BindingResult br,Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {String message = "";boolean success = false;if (br.hasErrors()) { message = "输入的信息有错误!";writeJsonResponse(response, success, message);return;}try {noticeService.updateNotice(notice);message = "新闻公告更新成功!";success = true;writeJsonResponse(response, success, message);} catch (Exception e) {e.printStackTrace();message = "新闻公告更新失败!";writeJsonResponse(response, success, message); }
}
/*删除新闻公告信息*/
@RequestMapping(value="/{noticeId}/delete",method=RequestMethod.GET)
public String delete(@PathVariable Integer noticeId,HttpServletRequest request) throws UnsupportedEncodingException {try {noticeService.deleteNotice(noticeId);request.setAttribute("message", "新闻公告删除成功!");return "message";} catch (Exception e) { e.printStackTrace();request.setAttribute("error", "新闻公告删除失败!");return "error";}}/*ajax方式删除多条新闻公告记录*/
@RequestMapping(value="/deletes",method=RequestMethod.POST)
public void delete(String noticeIds,HttpServletRequest request,HttpServletResponse response) throws IOException, JSONException {String message = "";boolean success = false;try { int count = noticeService.deleteNotices(noticeIds);success = true;message = count + "条记录删除成功";writeJsonResponse(response, success, message);} catch (Exception e) { //e.printStackTrace();message = "有记录存在外键约束,删除失败";writeJsonResponse(response, success, message);}
}/*按照查询条件导出新闻公告信息到Excel*/
@RequestMapping(value = { "/OutToExcel" }, method = {RequestMethod.GET,RequestMethod.POST})
public void OutToExcel(String title,String publishDate, Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {if(title == null) title = "";if(publishDate == null) publishDate = "";List noticeList = noticeService.queryNotice(title,publishDate);ExportExcelUtil ex = new ExportExcelUtil();String _title = "Notice信息记录"; String[] headers = { "公告id","标题","点击率","发布时间"};List dataset = new ArrayList(); for(int i=0;i

}

源码获取:关注底部gongzhonghao,021领取下载链接

相关内容

热门资讯

喜欢穿一身黑的男生性格(喜欢穿... 今天百科达人给各位分享喜欢穿一身黑的男生性格的知识,其中也会对喜欢穿一身黑衣服的男人人好相处吗进行解...
发春是什么意思(思春和发春是什... 本篇文章极速百科给大家谈谈发春是什么意思,以及思春和发春是什么意思对应的知识点,希望对各位有所帮助,...
网络用语zl是什么意思(zl是... 今天给各位分享网络用语zl是什么意思的知识,其中也会对zl是啥意思是什么网络用语进行解释,如果能碰巧...
为什么酷狗音乐自己唱的歌不能下... 本篇文章极速百科小编给大家谈谈为什么酷狗音乐自己唱的歌不能下载到本地?,以及为什么酷狗下载的歌曲不是...
家里可以做假山养金鱼吗(假山能... 今天百科达人给各位分享家里可以做假山养金鱼吗的知识,其中也会对假山能放鱼缸里吗进行解释,如果能碰巧解...
华为下载未安装的文件去哪找(华... 今天百科达人给各位分享华为下载未安装的文件去哪找的知识,其中也会对华为下载未安装的文件去哪找到进行解...
四分五裂是什么生肖什么动物(四... 本篇文章极速百科小编给大家谈谈四分五裂是什么生肖什么动物,以及四分五裂打一生肖是什么对应的知识点,希...
怎么往应用助手里添加应用(应用... 今天百科达人给各位分享怎么往应用助手里添加应用的知识,其中也会对应用助手怎么添加微信进行解释,如果能...
客厅放八骏马摆件可以吗(家里摆... 今天给各位分享客厅放八骏马摆件可以吗的知识,其中也会对家里摆八骏马摆件好吗进行解释,如果能碰巧解决你...
苏州离哪个飞机场近(苏州离哪个... 本篇文章极速百科小编给大家谈谈苏州离哪个飞机场近,以及苏州离哪个飞机场近点对应的知识点,希望对各位有...