@WebServlet("/admin/room")
public class RoomController extends HttpServlet {
RoomService roomService = new RoomServiceImpl();
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String opt = req.getParameter("opt");
if ("add".equals(opt)) {
req.getRequestDispatcher("/WEB-INF/default/admin/room/form.jsp").forward(req, resp);
} else if ("update".equals(opt)) {
String s = req.getParameter("id");
if (s != null && !"".equals(s)) {
Integer id = Integer.parseInt(s);
Room room = roomService.findById(id);
req.setAttribute("room", room);
req.getRequestDispatcher("/WEB-INF/default/admin/room/form.jsp").forward(req, resp);
} else {
resp.sendRedirect("./room");
}
} else {
List<Room> allRoom = roomService.getAllRoom();
req.setAttribute("rooms", allRoom);
req.getRequestDispatcher("/WEB-INF/default/admin/room/list.jsp").forward(req, resp);
}
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String opt = req.getParameter("opt");
if ("del".equals(opt)) {
String id = req.getParameter("id");
if (id != null && !"".equals(id)) {
roomService.del(id);
}
doGet(req, resp);
} else if ("save".equals(opt)) {
String roomId1 = req.getParameter("roomId");
int roomId = roomId1 == "" ? 0 : Integer.parseInt(roomId1);
String roomNumber = req.getParameter("roomNumber");
double area = Double.parseDouble(req.getParameter("area"));
int capacity = Integer.parseInt(req.getParameter("capacity"));
double price = Double.parseDouble(req.getParameter("price"));
String hardware = req.getParameter("hardware");
Room room = new Room(roomId, roomNumber, area, capacity, price, hardware);
roomService.addRoom(room);
resp.sendRedirect("./room");
} else {
doGet(req, resp);
}
}
}
客房管理之客房标准管理控制器
最新推荐文章于 2022-09-16 09:41:20 发布