源码获取:博客首页 "资源" 里下载!
酒店管理系统-温情小筑后台管理系统
系统概要
项目主要功能包括:
住客管理:住客入住、住客列表;
房间管理:房间列表、添加房间、修改房间状态;
会员管理:新增会员、会员列表;
系统设置:网站信息、修改密码、清除缓存;
数据表:生成Excel并导出等功能,适合java新手学习;
技术选型
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路径中设置为/,注意路径中不要带有项目名,否则会导致项目运行异常;
房间管理后台控制器:
/*** 房间管理后台控制器* @author yy**/@RequestMapping("/admin/room")@Controllerpublic class RoomController {@Autowiredprivate RoomTypeService roomTypeService;@Autowiredprivate RoomService roomService;@Autowiredprivate FloorService floorService;/*** 房间管理列表页面* @param model* @return*/@RequestMapping(value="/list",method=RequestMethod.GET)public ModelAndView list(ModelAndView model){model.addObject("roomTypeList", roomTypeService.findAll());model.addObject("floorList", floorService.findAll());model.setViewName("room/list");return model;}/*** 房间信息添加操作* @param roomType* @return*/@RequestMapping(value="/add",method=RequestMethod.POST)@ResponseBodypublic Map<String, String> add(Room room){Map<String, String> ret = new HashMap<String, String>();if(room == null){ret.put("type", "error");ret.put("msg", "请填写正确的房间信息!");return ret;}if(StringUtils.isEmpty(room.getSn())){ret.put("type", "error");ret.put("msg", "房间编号不能为空!");return ret;}if(room.getRoomTypeId() == null){ret.put("type", "error");ret.put("msg", "请选择房间类型!");return ret;}if(room.getFloorId() == null){ret.put("type", "error");ret.put("msg", "请选择房间所属楼层!");return ret;}if(isExist(room.getSn(), 0l)){ret.put("type", "error");ret.put("msg", "该房间编号已经存在!");return ret;}if(roomService.add(room) <= 0){ret.put("type", "error");ret.put("msg", "添加失败,请联系管理员!");return ret;}ret.put("type", "success");ret.put("msg", "添加成功!");return ret;}/*** 房间信息编辑操作* @param roomType* @return*/@RequestMapping(value="/edit",method=RequestMethod.POST)@ResponseBodypublic Map<String, String> edit(Room room){Map<String, String> ret = new HashMap<String, String>();if(room == null){ret.put("type", "error");ret.put("msg", "请填写正确的房间信息!");return ret;}if(StringUtils.isEmpty(room.getSn())){ret.put("type", "error");ret.put("msg", "房间编号不能为空!");return ret;}if(room.getRoomTypeId() == null){ret.put("type", "error");ret.put("msg", "请选择房间类型!");return ret;}if(room.getFloorId() == null){ret.put("type", "error");ret.put("msg", "请选择房间所属楼层!");return ret;}if(isExist(room.getSn(), room.getId())){ret.put("type", "error");ret.put("msg", "该房间编号已经存在!");return ret;}if(roomService.edit(room) <= 0){ret.put("type", "error");ret.put("msg", "修改失败,请联系管理员!");return ret;}ret.put("type", "success");ret.put("msg", "修改成功!");return ret;}/*** 分页查询房间信息* @param sn* @param page* @return*/@RequestMapping(value="/list",method=RequestMethod.POST)@ResponseBodypublic Map<String,Object> list(@RequestParam(name="sn",defaultValue="") String sn,@RequestParam(name="status",required=false) Integer status,@RequestParam(name="roomTypeId",required=false) Long roomTypeId,@RequestParam(name="floorId",required=false) Long floorId,Page page){Map<String,Object> ret = new HashMap<String, Object>();Map<String,Object> queryMap = new HashMap<String, Object>();queryMap.put("sn", sn);queryMap.put("status", status);queryMap.put("roomTypeId", roomTypeId);queryMap.put("floorId", floorId);queryMap.put("offset", page.getOffset());queryMap.put("pageSize", page.getRows());ret.put("rows", roomService.findList(queryMap));ret.put("total", roomService.getTotal(queryMap));return ret;}/*** 房间信息删除操作* @param id* @return*/@RequestMapping(value="/delete",method=RequestMethod.POST)@ResponseBodypublic Map<String, String> delete(Long id){Map<String, String> ret = new HashMap<String, String>();if(id == null){ret.put("type", "error");ret.put("msg", "请选择要删除的信息!");return ret;}try {if(roomService.delete(id) <= 0){ret.put("type", "error");ret.put("msg", "删除失败,请联系管理员!");return ret;}} catch (Exception e) {// TODO: handle exceptionret.put("type", "error");ret.put("msg", "该房间下存在订单信息,请先删除该房间下的所有订单信息!");return ret;}ret.put("type", "success");ret.put("msg", "删除成功!");return ret;}/*** 判断房间编号是否存在* @param sn* @param id* @return*/private boolean isExist(String sn,Long id){Room findBySn = roomService.findBySn(sn);if(findBySn == null)return false;if(findBySn.getId().longValue() == id.longValue())return false;return true;}}
用户管理控制器:
/*** 用户管理控制器* @author yy**/@RequestMapping("/admin/user")@Controllerpublic class UserController {@Autowiredprivate UserService userService;@Autowiredprivate RoleService roleService;/*** 用户列表页面* @param model* @return*/@RequestMapping(value="/list",method=RequestMethod.GET)public ModelAndView list(ModelAndView model){Map<String, Object> queryMap = new HashMap<String, Object>();model.addObject("roleList", roleService.findList(queryMap));model.setViewName("user/list");return model;}/*** 获取用户列表* @param page* @param username* @param roleId* @param sex* @return*/@RequestMapping(value="/list",method=RequestMethod.POST)@ResponseBodypublic Map<String, Object> getList(Page page,@RequestParam(name="username",required=false,defaultValue="") String username,@RequestParam(name="roleId",required=false) Long roleId,@RequestParam(name="sex",required=false) Integer sex){Map<String, Object> ret = new HashMap<String, Object>();Map<String, Object> queryMap = new HashMap<String, Object>();queryMap.put("username", username);queryMap.put("roleId", roleId);queryMap.put("sex", sex);queryMap.put("offset", page.getOffset());queryMap.put("pageSize", page.getRows());ret.put("rows", userService.findList(queryMap));ret.put("total", userService.getTotal(queryMap));return ret;}/*** 添加用户* @param user* @return*/@RequestMapping(value="/add",method=RequestMethod.POST)@ResponseBodypublic Map<String, String> add(User user){Map<String, String> ret = new HashMap<String, String>();if(user == null){ret.put("type", "error");ret.put("msg", "请填写正确的用户信息!");return ret;}if(StringUtils.isEmpty(user.getUsername())){ret.put("type", "error");ret.put("msg", "请填写用户名!");return ret;}if(StringUtils.isEmpty(user.getPassword())){ret.put("type", "error");ret.put("msg", "请填写密码!");return ret;}if(user.getRoleId() == null){ret.put("type", "error");ret.put("msg", "请选择所属角色!");return ret;}if(isExist(user.getUsername(), 0l)){ret.put("type", "error");ret.put("msg", "该用户名已经存在,请重新输入!");return ret;}if(userService.add(user) <= 0){ret.put("type", "error");ret.put("msg", "用户添加失败,请联系管理员!");return ret;}ret.put("type", "success");ret.put("msg", "角色添加成功!");return ret;}/*** 编辑用户* @param user* @return*/@RequestMapping(value="/edit",method=RequestMethod.POST)@ResponseBodypublic Map<String, String> edit(User user){Map<String, String> ret = new HashMap<String, String>();if(user == null){ret.put("type", "error");ret.put("msg", "请填写正确的用户信息!");return ret;}if(StringUtils.isEmpty(user.getUsername())){ret.put("type", "error");ret.put("msg", "请填写用户名!");return ret;}//if(StringUtils.isEmpty(user.getPassword())){//ret.put("type", "error");//ret.put("msg", "请填写密码!");//return ret;//}if(user.getRoleId() == null){ret.put("type", "error");ret.put("msg", "请选择所属角色!");return ret;}if(isExist(user.getUsername(), user.getId())){ret.put("type", "error");ret.put("msg", "该用户名已经存在,请重新输入!");return ret;}if(userService.edit(user) <= 0){ret.put("type", "error");ret.put("msg", "用户添加失败,请联系管理员!");return ret;}ret.put("type", "success");ret.put("msg", "角色添加成功!");return ret;}/*** 批量删除用户* @param ids* @return*/@RequestMapping(value="/delete",method=RequestMethod.POST)@ResponseBodypublic Map<String, String> delete(String ids){Map<String, String> ret = new HashMap<String, String>();if(StringUtils.isEmpty(ids)){ret.put("type", "error");ret.put("msg", "选择要删除的数据!");return ret;}if(ids.contains(",")){ids = ids.substring(0,ids.length()-1);}if(userService.delete(ids) <= 0){ret.put("type", "error");ret.put("msg", "用户删除失败,请联系管理员!");return ret;}ret.put("type", "success");ret.put("msg", "用户删除成功!");return ret;}/*** 上传图片* @param photo* @param request* @return*/@RequestMapping(value="/upload_photo",method=RequestMethod.POST)@ResponseBodypublic Map<String, String> uploadPhoto(MultipartFile photo,HttpServletRequest request){Map<String, String> ret = new HashMap<String, String>();if(photo == null){ret.put("type", "error");ret.put("msg", "选择要上传的文件!");return ret;}if(photo.getSize() > 1024*1024*1024){ret.put("type", "error");ret.put("msg", "文件大小不能超过10M!");return ret;}//获取文件后缀String suffix = photo.getOriginalFilename().substring(photo.getOriginalFilename().lastIndexOf(".")+1,photo.getOriginalFilename().length());if(!"jpg,jpeg,gif,png".toUpperCase().contains(suffix.toUpperCase())){ret.put("type", "error");ret.put("msg", "请选择jpg,jpeg,gif,png格式的图片!");return ret;}String savePath = request.getServletContext().getRealPath("/") + "/resources/upload/";File savePathFile = new File(savePath);if(!savePathFile.exists()){//若不存在改目录,则创建目录savePathFile.mkdir();}String filename = new Date().getTime()+"."+suffix;try {//将文件保存至指定目录photo.transferTo(new File(savePath+filename));}catch (Exception e) {// TODO Auto-generated catch blockret.put("type", "error");ret.put("msg", "保存文件异常!");e.printStackTrace();return ret;}ret.put("type", "success");ret.put("msg", "用户删除成功!");ret.put("filepath",request.getServletContext().getContextPath() + "/resources/upload/" + filename );return ret;}/*** 判断该用户名是否存在* @param username* @param id* @return*/private boolean isExist(String username,Long id){User user = userService.findByUsername(username);if(user == null)return false;if(user.getId().longValue() == id.longValue())return false;return true;}}
系统操作类控制器:
/*** 系统操作类控制器* @author yy**/@Controller@RequestMapping("/system")public class SystemController {@Autowiredprivate UserService userService;@Autowiredprivate RoleService roleService;@Autowiredprivate AuthorityService authorityService;@Autowiredprivate MenuService menuService;@Autowiredprivate LogService logService;/*** 系统登录后的主页* @param model* @return*/@RequestMapping(value="/index",method=RequestMethod.GET)public ModelAndView index(ModelAndView model,HttpServletRequest request){List<Menu> userMenus = (List<Menu>)request.getSession().getAttribute("userMenus");model.addObject("topMenuList", MenuUtil.getAllTopMenu(userMenus));model.addObject("secondMenuList", MenuUtil.getAllSecondMenu(userMenus));model.setViewName("system/index");return model;//WEB-INF/views/+system/index+.jsp = WEB-INF/views/system/index.jsp}/*** 系统登录后的欢迎页* @param model* @return*/@RequestMapping(value="/welcome",method=RequestMethod.GET)public ModelAndView welcome(ModelAndView model){model.setViewName("system/welcome");return model;}/*** 登陆页面* @param model* @return*/@RequestMapping(value="/login",method=RequestMethod.GET)public ModelAndView login(ModelAndView model){model.setViewName("system/login");return model;}/*** 登录表单提交处理控制器* @param user* @param cpacha* @return*/@RequestMapping(value="/login",method=RequestMethod.POST)@ResponseBodypublic Map<String, String> loginAct(User user,String cpacha,HttpServletRequest request){Map<String, String> ret = new HashMap<String, String>();if(user == null){ret.put("type", "error");ret.put("msg", "请填写用户信息!");return ret;}if(StringUtils.isEmpty(cpacha)){ret.put("type", "error");ret.put("msg", "请填写验证码!");return ret;}if(StringUtils.isEmpty(user.getUsername())){ret.put("type", "error");ret.put("msg", "请填写用户名!");return ret;}if(StringUtils.isEmpty(user.getPassword())){ret.put("type", "error");ret.put("msg", "请填写密码!");return ret;}Object loginCpacha = request.getSession().getAttribute("loginCpacha");if(loginCpacha == null){ret.put("type", "error");ret.put("msg", "会话超时,请刷新页面!");return ret;}if(!cpacha.toUpperCase().equals(loginCpacha.toString().toUpperCase())){ret.put("type", "error");ret.put("msg", "验证码错误!");logService.add("用户名为"+user.getUsername()+"的用户登录时输入验证码错误!");return ret;}User findByUsername = userService.findByUsername(user.getUsername());if(findByUsername == null){ret.put("type", "error");ret.put("msg", "该用户名不存在!");logService.add("登录时,用户名为"+user.getUsername()+"的用户不存在!");return ret;}if(!user.getPassword().equals(findByUsername.getPassword())){ret.put("type", "error");ret.put("msg", "密码错误!");logService.add("用户名为"+user.getUsername()+"的用户登录时输入密码错误!");return ret;}//说明用户名密码及验证码都正确//此时需要查询用户的角色权限Role role = roleService.find(findByUsername.getRoleId());List<Authority> authorityList = authorityService.findListByRoleId(role.getId());//根据角色获取权限列表String menuIds = "";for(Authority authority:authorityList){menuIds += authority.getMenuId() + ",";}if(!StringUtils.isEmpty(menuIds)){menuIds = menuIds.substring(0,menuIds.length()-1);}List<Menu> userMenus = menuService.findListByIds(menuIds);//把角色信息、菜单信息放到session中request.getSession().setAttribute("admin", findByUsername);request.getSession().setAttribute("role", role);request.getSession().setAttribute("userMenus", userMenus);ret.put("type", "success");ret.put("msg", "登录成功!");logService.add("用户名为{"+user.getUsername()+"},角色为{"+role.getName()+"}的用户登录成功!");return ret;}/*** 后台退出注销功能* @param request* @return*/@RequestMapping(value="/logout",method=RequestMethod.GET)public String logout(HttpServletRequest request){HttpSession session = request.getSession();session.setAttribute("admin", null);session.setAttribute("role", null);request.getSession().setAttribute("userMenus", null);return "redirect:login";}/*** 修改密码页面* @param model* @return*/@RequestMapping(value="/edit_password",method=RequestMethod.GET)public ModelAndView editPassword(ModelAndView model){model.setViewName("system/edit_password");return model;}@RequestMapping(value="/edit_password",method=RequestMethod.POST)@ResponseBodypublic Map<String, String> editPasswordAct(String newpassword,String oldpassword,HttpServletRequest request){Map<String, String> ret = new HashMap<String, String>();if(StringUtils.isEmpty(newpassword)){ret.put("type", "error");ret.put("msg", "请填写新密码!");return ret;}User user = (User)request.getSession().getAttribute("admin");if(!user.getPassword().equals(oldpassword)){ret.put("type", "error");ret.put("msg", "原密码错误!");return ret;}user.setPassword(newpassword);if(userService.editPassword(user) <= 0){ret.put("type", "error");ret.put("msg", "密码修改失败,请联系管理员!");return ret;}ret.put("type", "success");ret.put("msg", "密码修改成功!");logService.add("用户名为{"+user.getUsername()+"},的用户成功修改密码!");return ret;} /*** 本系统所有的验证码均采用此方法* @param vcodeLen* @param width* @param height* @param cpachaType:用来区别验证码的类型,传入字符串* @param request* @param response*/@RequestMapping(value="/get_cpacha",method=RequestMethod.GET)public void generateCpacha(@RequestParam(name="vl",required=false,defaultValue="4") Integer vcodeLen,@RequestParam(name="w",required=false,defaultValue="100") Integer width,@RequestParam(name="h",required=false,defaultValue="30") Integer height,@RequestParam(name="type",required=true,defaultValue="loginCpacha") String cpachaType,HttpServletRequest request,HttpServletResponse response){CpachaUtil cpachaUtil = new CpachaUtil(vcodeLen, width, height);String generatorVCode = cpachaUtil.generatorVCode();request.getSession().setAttribute(cpachaType, generatorVCode);BufferedImage generatorRotateVCodeImage = cpachaUtil.generatorRotateVCodeImage(generatorVCode, true);try {ImageIO.write(generatorRotateVCodeImage, "gif", response.getOutputStream());} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}
源码获取:博客首页 "资源" 里下载!