From 9019d17f1ffe1debb7824ce58ea0af179b219c46 Mon Sep 17 00:00:00 2001 From: pho6e2qjw <1563847437@qq.com> Date: Tue, 25 Jun 2024 23:26:18 +0800 Subject: [PATCH] Add ReserveController.java --- ReserveController.java | 104 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 ReserveController.java diff --git a/ReserveController.java b/ReserveController.java new file mode 100644 index 0000000..68c39d1 --- /dev/null +++ b/ReserveController.java @@ -0,0 +1,104 @@ +//在线预约 +package com.power.travel.controller; + +import com.power.travel.core.Result; +import com.power.travel.service.ReserveService; +import com.power.travel.model.Attractions; +import com.power.travel.model.Hotel; +import com.power.travel.model.UserAttractions; +import com.power.travel.model.UserHotel; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.web.PageableDefault; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.servlet.http.HttpServletRequest; +import java.util.List; + +@Controller +@RequestMapping("/reserve") +public class ReserveController { + + @Autowired + private ReserveService reserveService; + + //这是一个Spring MVC的注解,它表示当用户访问/travelRouteListUI这个URL时,下面的方法会被调用。 + @RequestMapping("/reserveHotelListUI") + public String reserveHotelListUI(Model model, @ModelAttribute("searchName") String searchName, @PageableDefault(size = 10) Pageable pageable) { + Page page = reserveService.reserveHotelListUI(searchName, pageable); + List top10Hotel = reserveService.getTop10Hotel(); + List top10Attractions = reserveService.getTop10Attractions(); + model.addAttribute("top10Hotel", top10Hotel); + model.addAttribute("top10Attractions", top10Attractions); + model.addAttribute("page", page); + return "reserve/reserve-hotel"; + } + + @RequestMapping("/hotelDetailsUI") + public String hotelDetailsUI(Model model, HttpServletRequest request, @RequestParam(name = "id") String id) { + Hotel hotel = reserveService.findHotelById(id); + //如果用户显示已经预约,就是查看预约列表 + Boolean flag = reserveService.isReserveHotel(request, id); + List top10Hotel = reserveService.getTop10Hotel(); + List top10Attractions = reserveService.getTop10Attractions(); + model.addAttribute("top10Hotel", top10Hotel); + model.addAttribute("top10Attractions", top10Attractions); + model.addAttribute("hotel", hotel); + model.addAttribute("flag", flag); + return "reserve/reserve-hotel-details"; + } + + @RequestMapping("/reserveManageUI") + public String reserveManageUI(Model model, HttpServletRequest request) { + List userHotelList = reserveService.getReserveHotelByUser(request); + List userAttractionsList = reserveService.getReserveAttractionsByUser(request); + model.addAttribute("userHotelList", userHotelList); + model.addAttribute("userAttractionsList",userAttractionsList); + return "reserve/reserve-user-manage"; + } + + @RequestMapping("/cancelReserve") + @ResponseBody + public Result cancelReserve(HttpServletRequest request, String id) { + return reserveService.cancelReserve(request,id); + } + + @RequestMapping("/reserveAttractionsListUI") + public String reserveAttractionsListUI(Model model, @ModelAttribute("searchName") String searchName, @PageableDefault(size = 10) Pageable pageable) { + Page page = reserveService.reserveAttractionsListUI(searchName,pageable); + List top10Hotel = reserveService.getTop10Hotel(); + List top10Attractions = reserveService.getTop10Attractions(); + model.addAttribute("top10Hotel", top10Hotel); + model.addAttribute("top10Attractions", top10Attractions); + model.addAttribute("page", page); + return "reserve/reserve-attractions"; + } + + @RequestMapping("/attractionsDetailsUI") + public String attractionsDetailsUI(Model model, HttpServletRequest request, @RequestParam(name = "id") String id) { + Attractions attractions = reserveService.findAttractionsById(id); + //如果用户显示已经预约,就是查看预约列表 + Boolean flag = reserveService.isReserveAttractions(request, id); + List top10Hotel = reserveService.getTop10Hotel(); + List top10Attractions = reserveService.getTop10Attractions(); + model.addAttribute("top10Hotel", top10Hotel); + model.addAttribute("top10Attractions", top10Attractions); + model.addAttribute("attractions", attractions); + model.addAttribute("flag", flag); + return "reserve/reserve-attractions-details"; + } + + + @RequestMapping("/cancelAttractionsReserve") + @ResponseBody + public Result cancelAttractionsReserve(HttpServletRequest request,String id) { + return reserveService.cancelAttractionsReserve(request,id); + } + +}