@Controller @RequestMapping("/orders") public class OrdersController { @Resource private OrdersService ordersService; /** * 添加订单 * @param orders * @return */ @RequestMapping("/addOrders") @ResponseBody public String addOrders(Orders orders){ Map<String,Object> map = new HashMap<String,Object>(); //调用添加订单的方法 if(ordersService.addOrders(orders)>0){ map.put(SystemConstant.SUCCESS,true); map.put(SystemConstant.MESSAGE,"酒店预订成功"); }else{ map.put(SystemConstant.SUCCESS,false); map.put(SystemConstant.MESSAGE,"酒店预订失败,请重试!"); } return JSON.toJSONString(map); } }
/** * 房间管理控制层 */ @Controller @RequestMapping("/room") public class RoomController { @Resource private RoomService roomService; @Resource private RoomTypeService roomTypeService; /** * 查询房间详情 * @param id * @param model * @return */ @RequestMapping("/{id}.html") public String detail(@PathVariable Integer id, Model model){ //调用查询房间详情的方法 Room room = roomService.findById(id); //将数据放到模型中 model.addAttribute("room",room); return "detail"; } /** * 查询全部房间列表 * @param model * @return */ @RequestMapping("/list.html") public String list(Model model){ //调用查询所有房型列表的方法 List<RoomType> roomTypeList = roomTypeService.findRoomTypeList(null); //创建查询条件类 RoomVo roomVo = new RoomVo(); roomVo.setStatus(3);//可预订 //查询房间列表 List<Room> roomList = roomService.findRoomListByPage(roomVo); //将数据放到模型中 model.addAttribute("roomTypeList",roomTypeList); model.addAttribute("roomList",roomList); return "hotelList"; } /** * 根据房型查询房间列表 * @param model * @return */ @RequestMapping("/list/{id}") public String list(@PathVariable Integer id,Model model){ //调用查询所有房型列表的方法 List<RoomType> roomTypeList = roomTypeService.findRoomTypeList(null); //创建查询条件类 RoomVo roomVo = new RoomVo(); roomVo.setRoomtypeid(id);//房型ID roomVo.setStatus(3);//可预订 //查询房间列表 List<Room> roomList = roomService.findRoomListByPage(roomVo); //将数据放到模型中 model.addAttribute("roomTypeList",roomTypeList); model.addAttribute("roomList",roomList); model.addAttribute("typeId",id);//将当前选中的房型ID保存到模型中,目的是在页面中回显选中的文本(改变选中的颜色) return "hotelList"; } }
/** * 用户管理控制层 */ @Controller @RequestMapping("/user") public class UserController { @Autowired private UserService userService; /** * 注册 * @param user * @return */ @RequestMapping("/register") @ResponseBody public String register(User user){ Map<String,Object> map = new HashMap<String,Object>(); //调用注册的方法 if(userService.addUser(user)>0){ map.put(SystemConstant.SUCCESS,true); map.put(SystemConstant.MESSAGE,"恭喜你,注册成功!"); }else{ map.put(SystemConstant.SUCCESS,false); map.put(SystemConstant.MESSAGE,"很遗憾,注册失败,请重新尝试!"); } return JSON.toJSONString(map); } /** * 登录 * @param * @return */ @RequestMapping("/login") @ResponseBody public String login(String loginName, String password, HttpSession Session){ Map<String,Object> map = new HashMap<String,Object>(); //调用注册的方法 User loginUser = userService.login(loginName, password); //登录判断 if(loginUser!=null){ //将密码清空 loginUser.setPassword(null); map.put(SystemConstant.SUCCESS,true); //保存登录用户信息到session中 Session.setAttribute(SystemConstant.FRONT_LOGIN_USER,loginUser); }else{ map.put(SystemConstant.SUCCESS,false); map.put(SystemConstant.MESSAGE,"用户名或密码错误,请重新登录!"); } return JSON.toJSONString(map); } /** * 根据用户名查询用户信息 * @param loginName * @return */ @RequestMapping("/checkName") @ResponseBody public String checkName(String loginName){ Map<String,Object> map = new HashMap<String,Object>(); //调用注册的方法 if(userService.findUserByName(loginName)!=null){ map.put(SystemConstant.EXISI,true); map.put(SystemConstant.MESSAGE,"用户名存在,请重新输入"); }else{ map.put(SystemConstant.EXISI,false); } return JSON.toJSONString(map); } }