From 6cd4d68e5e9d2a01aa9b51baca90eb479cc9522a Mon Sep 17 00:00:00 2001 From: pfor58hiw <2123898275@qq.com> Date: Wed, 26 Jun 2024 08:19:30 +0800 Subject: [PATCH] Add IndexController --- IndexController | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 IndexController diff --git a/IndexController b/IndexController new file mode 100644 index 0000000..8f71ffc --- /dev/null +++ b/IndexController @@ -0,0 +1,38 @@ +package com.power.travel.controller; + +import com.power.travel.model.TravelRoute; +import com.power.travel.service.ReserveService; +import com.power.travel.service.RouteService; +import com.power.travel.service.StrategyService; +import com.power.travel.model.Attractions; +import com.power.travel.model.Hotel; +import com.power.travel.model.TravelStrategy; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestMapping; + +import java.util.List; +//@Controller:这是一个Spring MVC的注解,它表示这个类是一个控制器类,用于处理用户的请求 +@Controller +public class IndexController { + @Autowired + private ReserveService reserveService; + @Autowired + private RouteService routeService; + @Autowired + private StrategyService strategyService; +// index(Model model):这是IndexController类的一个方法,它用于处理用户访问首页的请求 + @RequestMapping("/") + public String index(Model model) { + List top10Hotel = reserveService.getTop10Hotel(); + List top10Attractions = reserveService.getTop10Attractions(); + List top10Route = routeService.findTop10Route(); + List top10Strategy = strategyService.findTop10Strategy(); + model.addAttribute("top10Strategy",top10Strategy); + model.addAttribute("top10Route", top10Route); + model.addAttribute("top10Hotel", top10Hotel); + model.addAttribute("top10Attractions", top10Attractions); + return "index"; + } +}