首页

房间预定

房间预定

管理员登录

部门管理

楼层管理

房型管理

营业额报表

员工管理

角色管理

开发报表

首页

开发工具: Idea/Eclipse
数据库: mysql
Jar包仓库: Maven
前段框架:Html/JSP/LayUI
后端框架: Spring+SpringMVC+Mybatis+SpringBoot

package com.song.controller;

import com.alibaba.fastjson.JSON;
import com.song.pojo.Orders;
import com.song.service.OrdersService;
import com.song.utils.SystemConstant;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@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);
    }

}

package com.song.controller;

import com.song.pojo.Room;
import com.song.pojo.RoomType;
import com.song.service.RoomService;
import com.song.service.RoomTypeService;
import com.song.vo.RoomVo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;


@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";
    }
}

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐