三、部分代码
IndexController
package com.sjsq.travel.controller; import com.sjsq.travel.model.Attractions; import com.sjsq.travel.model.Hotel; import com.sjsq.travel.model.TravelRoute; import com.sjsq.travel.model.TravelStrategy; import com.sjsq.travel.service.ReserveService; import com.sjsq.travel.service.RouteService; import com.sjsq.travel.service.StrategyService; 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 public class IndexController { @Autowired private ReserveService reserveService; @Autowired private RouteService routeService; @Autowired private StrategyService strategyService; @RequestMapping("/") public String index(Model model) { List<Hotel> top10Hotel = reserveService.getTop10Hotel(); List<Attractions> top10Attractions = reserveService.getTop10Attractions(); List<TravelRoute> top10Route = routeService.findTop10Route(); List<TravelStrategy> top10Strategy = strategyService.findTop10Strategy(); model.addAttribute("top10Strategy", top10Strategy); model.addAttribute("top10Route", top10Route); model.addAttribute("top10Hotel", top10Hotel); model.addAttribute("top10Attractions", top10Attractions); return "index"; } }
LoginController
package com.sjsq.travel.controller; import com.sjsq.travel.core.Result; import com.sjsq.travel.model.User; import com.sjsq.travel.service.LoginService; 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 org.springframework.web.bind.annotation.ResponseBody; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @Controller public class LoginController { @Autowired private LoginService loginService; @RequestMapping("/loginUI") public String loginUI() { return "login/index-login"; } @RequestMapping("/login") @ResponseBody public Result login(Model model, User user, HttpServletResponse response) { return loginService.login(user, response); } @RequestMapping("/logout") public String logout(HttpServletRequest request, HttpServletResponse response) { loginService.logout(request, response); //SpringMVC重定向 return "redirect:/"; } @RequestMapping("/registerUI") public String registerUI() { return "login/index-register"; } @RequestMapping("/register") @ResponseBody public Result register(Model model, User user) { return loginService.register(user); } }
ReserveController
package com.sjsq.travel.controller; import com.sjsq.travel.core.Result; import com.sjsq.travel.model.Attractions; import com.sjsq.travel.model.Hotel; import com.sjsq.travel.model.UserAttractions; import com.sjsq.travel.model.UserHotel; import com.sjsq.travel.service.ReserveService; 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; @RequestMapping("/reserveHotelListUI") public String reserveHotelListUI(Model model, @ModelAttribute("searchName") String searchName, @PageableDefault(size = 10) Pageable pageable) { Page<Hotel> page = reserveService.reserveHotelListUI(searchName, pageable); List<Hotel> top10Hotel = reserveService.getTop10Hotel(); List<Attractions> 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<Hotel> top10Hotel = reserveService.getTop10Hotel(); List<Attractions> 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<UserHotel> userHotelList = reserveService.getReserveHotelByUser(request); List<UserAttractions> 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<Attractions> page = reserveService.reserveAttractionsListUI(searchName, pageable); List<Hotel> top10Hotel = reserveService.getTop10Hotel(); List<Attractions> 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<Hotel> top10Hotel = reserveService.getTop10Hotel(); List<Attractions> 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); } }
RouteController
package com.sjsq.travel.controller; import com.sjsq.travel.core.Result; import com.sjsq.travel.model.TravelRoute; import com.sjsq.travel.model.UserRoute; import com.sjsq.travel.service.RouteService; 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("/route") public class RouteController { @Autowired private RouteService routeService; @RequestMapping("/travelRouteListUI") public String travelRouteListUI(Model model, @ModelAttribute("searchName") String searchName, @PageableDefault(size = 10) Pageable pageable) { Page<TravelRoute> page = routeService.TravelRouteListUI(searchName, pageable); List<TravelRoute> top10Route = routeService.findTop10Route(); model.addAttribute("top10Route", top10Route); model.addAttribute("page", page); return "route/travelRoute"; } @RequestMapping("/travelRouteDetailsUI") public String travelRouteDetailsUI(Model model, HttpServletRequest request, @RequestParam(name = "id") String id) { TravelRoute travelRoute = routeService.findTravelRouteById(id); //如果用户显示已经关注,就是查看关注列表 Boolean flag = routeService.isRoute(request, id); List<TravelRoute> top10Route = routeService.findTop10Route(); model.addAttribute("top10Route", top10Route); model.addAttribute("travelRoute", travelRoute); model.addAttribute("flag", flag); return "route/travelRoute-details"; } @RequestMapping("/routeManageUI") public String routeManageUI(Model model, HttpServletRequest request) { List<UserRoute> userRouteList = routeService.getTravelRouteByUser(request); model.addAttribute("userRouteList", userRouteList); return "route/route-user-manage"; } @RequestMapping("/cancelTravelRouteReserve") @ResponseBody public Result cancelTravelRouteReserve(HttpServletRequest request, String id) { return routeService.cancelTravelRouteReserve(request, id); } }
StrategyController
package com.sjsq.travel.controller; import com.sjsq.travel.core.Result; import com.sjsq.travel.model.TravelStrategy; import com.sjsq.travel.model.UserStrategy; import com.sjsq.travel.service.StrategyService; 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<TravelStrategy> page = strategyService.TravelStrategyListUI(searchName, pageable); List<TravelStrategy> 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<TravelStrategy> 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<UserStrategy> userStrategyList = strategyService.getTravelStrategyByUser(request); List<TravelStrategy> 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<TravelStrategy> page = strategyService.PushStrategyListUI(request, searchName, pageable); List<TravelStrategy> top10Strategy = strategyService.findTop10Strategy(); model.addAttribute("top10Strategy", top10Strategy); model.addAttribute("page", page); return "strategy/pushStrategy"; } }
SystemController
package com.sjsq.travel.controller; import com.sjsq.travel.core.Result; import com.sjsq.travel.core.ResultGenerator; import com.sjsq.travel.model.*; import com.sjsq.travel.service.SystemService; 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.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @Controller @RequestMapping("/system") public class SystemController { @Autowired private SystemService systemService; @RequestMapping("") public String loginUI() { return "system/login/login"; } @RequestMapping("/login") @ResponseBody public Result login(SysUser sysUser, HttpServletResponse response) { return systemService.login(sysUser, response); } @RequestMapping("/userListUI") public String userListUI(Model model, @PageableDefault(size = 10) Pageable pageable) { Page<User> page = systemService.getUserPage(pageable); model.addAttribute("page", page); return "system/user/list"; } @RequestMapping("/saveUser") @ResponseBody public Result saveUser(User user) { return systemService.saveUser(user); } @RequestMapping("/getUserById") @ResponseBody public Result getUserById(String id) { return ResultGenerator.genSuccessResult(systemService.getUserById(id)); } @RequestMapping("/logout") public String logout(HttpServletRequest request, HttpServletResponse response) { systemService.logout(request, response); return "redirect:/system"; } @RequestMapping("/hotelListUI") public String hotelListUI(Model model, @PageableDefault(size = 10) Pageable pageable) { Page<Hotel> page = systemService.getHotelPage(pageable); model.addAttribute("page", page); return "system/hotel/list"; } @RequestMapping("/saveHotel") @ResponseBody public Result saveHotel(Hotel hotel) { return systemService.saveHotel(hotel); } @RequestMapping("/updateStatus") @ResponseBody public Result updateStatus(String id) { return systemService.updateStatus(id); } @RequestMapping("/getHotelById") @ResponseBody public Result getHotelById(String id) { return ResultGenerator.genSuccessResult(systemService.getHotelById(id)); } @RequestMapping("/attractionsListUI") public String attractionsListUI(Model model, @PageableDefault(size = 10) Pageable pageable) { Page<Attractions> page = systemService.getAttractionsPage(pageable); model.addAttribute("page", page); return "system/attractions/list"; } @RequestMapping("/getAttractionsById") @ResponseBody public Result getAttractionsById(String id) { return ResultGenerator.genSuccessResult(systemService.getAttractionsById(id)); } @RequestMapping("/updateAttractionsStatus") @ResponseBody public Result updateAttractionsStatus(String id) { return systemService.updateAttractionsStatus(id); } @RequestMapping("/saveAttractions") @ResponseBody public Result saveAttractions(Attractions attractions) { return systemService.saveAttractions(attractions); } @RequestMapping("/travelRouteListUI") public String travelRouteListUI(Model model, @PageableDefault(size = 10) Pageable pageable) { Page<TravelRoute> page = systemService.getTravelRoutePage(pageable); model.addAttribute("page", page); return "system/route/list"; } @RequestMapping("/getTravelRouteById") @ResponseBody public Result getTravelRouteById(String id) { return ResultGenerator.genSuccessResult(systemService.getTravelRouteById(id)); } @RequestMapping("/updateTravelRouteStatus") @ResponseBody public Result updateTravelRouteStatus(String id) { return systemService.updateTravelRouteStatus(id); } @RequestMapping("/saveTravelRoute") @ResponseBody public Result saveTravelRoute(TravelRoute travelRoute) { return systemService.saveTravelRoute(travelRoute); } @RequestMapping("/travelStrategyListUI") public String travelStrategyListUI(Model model, @PageableDefault(size = 10) Pageable pageable) { Page<TravelStrategy> page = systemService.getTravelStrategyPage(pageable); model.addAttribute("page", page); return "system/strategy/list"; } @RequestMapping("/getTravelStrategyById") @ResponseBody public Result getTravelStrategyById(String id) { return ResultGenerator.genSuccessResult(systemService.getTravelStrategyById(id)); } @RequestMapping("/updateTravelStrategyStatus") @ResponseBody public Result updateTravelStrategyStatus(String id) { return systemService.updateTravelStrategyStatus(id); } @RequestMapping("/saveTravelStrategy") @ResponseBody public Result saveTravelStrategy(HttpServletRequest request, TravelStrategy travelStrategy) { return systemService.saveTravelStrategy(request, travelStrategy); } }
UserCenterController
package com.sjsq.travel.controller; import com.sjsq.travel.core.Result; import com.sjsq.travel.model.User; import com.sjsq.travel.service.UserCenterService; import com.sjsq.travel.util.CookieUitl; 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 org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @Controller @RequestMapping("/user") public class UserCenterController { @Autowired private UserCenterService userCenterService; @RequestMapping("/centerUI") public String centerUI(Model model, HttpServletRequest request) { User user = userCenterService.getUser(request); model.addAttribute("user", user); return "center/user-center"; } @RequestMapping("/centerEditUI") public String centerEditUI(Model model, HttpServletRequest request) { User user = userCenterService.getUser(request); model.addAttribute("user", user); return "center/user-center-edit"; } @RequestMapping("/centerEdit") @ResponseBody public Result centerEdit(Model model, User user) { return userCenterService.centerEdit(user); } @RequestMapping("/centerEditPWUI") public String centerEditPWUI(Model model, HttpServletRequest request) { User user = userCenterService.getUser(request); model.addAttribute("id", user.getId()); return "center/user-center-editpw"; } @RequestMapping("/centerEditPW") @ResponseBody public Result centerEditPW(HttpServletRequest request, HttpServletResponse response, Model model, @RequestParam("id") String id, @RequestParam("oldPassword") String oldPassword, @RequestParam("newPassword") String newPassword) { return userCenterService.centerEditPW(request, response, id, oldPassword, newPassword); } }
四、其他
1.更多系统
更多JavaWeb系统请关注专栏。
https://blog.csdn.net/helongqiang/category_10020130.html
https://blog.csdn.net/helongqiang/category_10020130.html
3.运行项目
通过pom文件导入即可。
4.备注
如有侵权请联系我删除。
5.支持博主
如果您觉得此文对您有帮助,请点赞加关注加收藏。祝您生活愉快!