From 7361e7316e87c36401e1b1d8aedfb3b978270637 Mon Sep 17 00:00:00 2001 From: p96aetpbr <2691443110@qq.com> Date: Wed, 26 Jun 2024 08:30:52 +0800 Subject: [PATCH] Add StrategyController.java --- StrategyController.java | 81 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 StrategyController.java diff --git a/StrategyController.java b/StrategyController.java new file mode 100644 index 0000000..4ed1133 --- /dev/null +++ b/StrategyController.java @@ -0,0 +1,81 @@ +package com.power.travel.controller; + +import com.power.travel.core.Result; +import com.power.travel.service.StrategyService; +import com.power.travel.model.TravelStrategy; +import com.power.travel.model.UserStrategy; +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("/strategy") +public class StrategyController { + + @Autowired + private StrategyService strategyService; + + @RequestMapping("/travelStrategyListUI") + public String travelStrategyListUI(Model model, @ModelAttribute("searchName") String searchName, + @PageableDefault(size = 10) Pageable pageable) { + Page page = strategyService.TravelStrategyListUI(searchName, pageable); + List top10Strategy = strategyService.findTop10Strategy(); + model.addAttribute("top10Strategy", top10Strategy); + model.addAttribute("page", page); + return "strategy/travelStrategy"; + } + + @RequestMapping("/travelStrategyDetailsUI") + public String travelStrategyDetailsUI(Model model, HttpServletRequest request, @RequestParam(name = "id") String id) { + TravelStrategy travelStrategy = strategyService.findTravelStrategyById(id); + //如果用户显示已经关注,就是查看关注列表 + Boolean flag = strategyService.isStrategy(request, id); + List top10Strategy = strategyService.findTop10Strategy(); + model.addAttribute("top10Strategy", top10Strategy); + model.addAttribute("travelStrategy", travelStrategy); + model.addAttribute("flag", flag); + return "strategy/travelStrategy-details"; + } + + @RequestMapping("/cancelTravelStrategyReserve") + @ResponseBody + public Result cancelTravelStrategyReserve(HttpServletRequest request, String id) { + return strategyService.cancelTravelStrategyReserve(request, id); + } + + @RequestMapping("/strategyManageUI") + public String strategyManageUI(Model model, HttpServletRequest request) { + List userStrategyList = strategyService.getTravelStrategyByUser(request); + List top10Strategy = strategyService.findTop10Strategy(); + model.addAttribute("top10Strategy", top10Strategy); + model.addAttribute("userStrategyList", userStrategyList); + return "strategy/strategy-manage"; + } + + @RequestMapping("/saveTravelStrategy") + @ResponseBody + public Result saveTravelStrategy(HttpServletRequest request, TravelStrategy travelStrategy) { + return strategyService.saveTravelStrategy(request, travelStrategy); + } + +// 发布攻略请求并返回一个视图 + @RequestMapping("/pushStrategyListUI") + public String pushStrategyListUI(HttpServletRequest request, Model model, @ModelAttribute("searchName") + String searchName, @PageableDefault(size = 10) Pageable pageable) { + Page page = strategyService.PushStrategyListUI(request,searchName, pageable); + List top10Strategy = strategyService.findTop10Strategy(); + model.addAttribute("top10Strategy", top10Strategy); + model.addAttribute("page", page); + return "strategy/pushStrategy"; + } +}