您好,登錄后才能下訂單哦!
這篇文章主要為大家展示了“Java如何實現誠途旅游系統”,內容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領大家一起研究并學習一下“Java如何實現誠途旅游系統”這篇文章吧。
采用ssm架構實現的旅游網站系統 包括網站展示和后臺管理功能,網站主要是頁面瀏覽以及評論、制定旅游方案、智能推薦功能 后臺就是維護網站展示的內容,添加旅游景點、管理用戶、查看用戶的搜索記錄功能
/** * 控制器層 * */ @Controller @CrossOrigin @RequestMapping("/hotel") public class HotelController { @Autowired private HotelService hotelService; @Autowired private ScenicService scenicService; /** * 查詢全部酒店信息 * @return */ @ResponseBody @RequestMapping(value = "/list",method= RequestMethod.GET) public Result findAll(){ List<Hotel> all = hotelService.findAll(); return new Result(true, StatusCode.OK,"查詢成功",all,all.size()); } /** * 根據ID查詢 * @param id ID * @return */ @ResponseBody @RequestMapping(value="/{id}",method= RequestMethod.GET) public Result findById(@PathVariable Long id){ return new Result(true,StatusCode.OK,"查詢成功",hotelService.findById(id)); } /** * 酒店添加操作 * @param hotel */ @ResponseBody @RequestMapping(value = "/add",method=RequestMethod.POST) public Result add(Hotel hotel){ if(StringUtils.isEmpty(hotel.getName())){ return new Result(false,StatusCode.ERROR,"請填寫酒店名稱"); } if(StringUtils.isEmpty(hotel.getImg())){ return new Result(false,StatusCode.ERROR,"請上傳酒店封面圖片"); } if(StringUtils.isEmpty(hotel.getAddr())){ return new Result(false,StatusCode.ERROR,"請填寫酒店地址"); } if(StringUtils.isEmpty(hotel.getMiaoshu())){ return new Result(false,StatusCode.ERROR,"請填寫酒店描述"); } hotel.setCommentCount(0); hotel.setStar(0); if(hotelService.add(hotel)==null){ return new Result(false,StatusCode.ERROR,"酒店添加失敗"); } return new Result(true,StatusCode.OK,"添加成功"); } /** * 分頁+多條件查詢 * @param searchMap 查詢條件封裝 * @param page 頁碼 * @param size 頁大小 * @return 分頁結果 */ @ResponseBody @RequestMapping(value="/search/{page}/{size}",method=RequestMethod.POST) public Result findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){ Page<Hotel> pageList = hotelService.findSearch(searchMap, page, size); return new Result(true,StatusCode.OK,"查詢成功", new PageResult<Hotel>(pageList.getTotalElements(), pageList.getContent()) ); } /** * 根據條件查詢 * @param searchMap * @return */ @ResponseBody @RequestMapping(value="/search",method = RequestMethod.POST) public Result findSearch( @RequestBody Map searchMap){ return new Result(true,StatusCode.OK,"查詢成功",hotelService.findSearch(searchMap)); } /** * 修改 * @param hotel */ @ResponseBody @RequestMapping(value="/edit",method= RequestMethod.PUT) public Result update(Hotel hotel){ Hotel hotelById = hotelService.findById(hotel.getId()); if(hotelById==null){ return new Result(false,StatusCode.ERROR,"該酒店信息不存在"); } if(StringUtils.isEmpty(hotel.getName())){ return new Result(false,StatusCode.ERROR,"請填寫酒店名稱"); } BeanUtils.copyProperties(hotel,hotelById,"id","img","miaoshu","day","startdate","addr","commentCount"); if(hotelService.update(hotelById)==null){ return new Result(false,StatusCode.ERROR,"酒店編輯失敗"); } return new Result(true,StatusCode.OK,"修改成功"); } /** * 刪除 * @param id */ @ResponseBody @RequestMapping(value="/{id}",method= RequestMethod.DELETE) public Result delete(@PathVariable String id ){ hotelService.deleteById(id); return new Result(true,StatusCode.OK,"刪除成功"); } /** * 酒店列表跳轉路徑 * @return */ @RequestMapping(value = "/hotelList") public String hotelList(){ return "admin/hotelmanage/hotelList"; } @RequestMapping(value = "/hotelAdd") public String hotelAdd(){ return "admin/hotelmanage/hotelAdd"; } /** * 查詢單個酒店 * @param model * @param id * @return */ @RequestMapping("/oneAttr") public String One_attr(Model model, Long id){ Hotel scenic=hotelService.findById(id); model.addAttribute("oneAttr",scenic); return "page/hotelDetail"; } @RequestMapping("/local") public String localRefresh(Model model,Long id) { Hotel hotel=hotelService.findById(id); // Sort sort=new Sort(Sort.Direction.DESC,"star"); System.out.println("1111"+hotel.toString()); List<Scenic> scenics=scenicService.findByCountryLike(hotel.getAddr()); System.out.println("2222"+scenics.toString()); Collections.sort(scenics, new Comparator<Scenic>() { @Override public int compare(Scenic o1, Scenic o2) { if (o1.getStart()<o2.getStart()){ return 2; } if (o1.getStart().equals(o2.getStart()) ){ return 1; } return -1; } }); if (scenics.size()>=4){ List newList=scenics.subList(0,3); model.addAttribute("scenics",newList); }else { model.addAttribute("scenics",scenics); } return "page/hotelDetail::table_refresh"; } }
/** * 控制器層 * */ @Controller @CrossOrigin @RequestMapping("/admin") public class AdminController { @Autowired private AdminService adminService; @Autowired BCryptPasswordEncoder encoder; /** * 查詢全部數據 * @return */ @ResponseBody @RequestMapping(method= RequestMethod.GET) public Result findAll(){ return new Result(true, StatusCode.OK,"查詢成功",adminService.findAll()); } /** * 根據ID查詢 * @param id ID * @return */ @ResponseBody @RequestMapping(value="/{id}",method= RequestMethod.GET) public Result findById(@PathVariable Long id){ return new Result(true,StatusCode.OK,"查詢成功",adminService.findById(id)); } /** * 分頁+多條件查詢 * @param searchMap 查詢條件封裝 * @param page 頁碼 * @param size 頁大小 * @return 分頁結果 */ @ResponseBody @RequestMapping(value="/search/{page}/{size}",method=RequestMethod.POST) public Result findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){ Page<Admin> pageList = adminService.findSearch(searchMap, page, size); return new Result(true,StatusCode.OK,"查詢成功", new PageResult<Admin>(pageList.getTotalElements(), pageList.getContent()) ); } /** * 根據條件查詢 * @param searchMap * @return */ @ResponseBody @RequestMapping(value="/search",method = RequestMethod.POST) public Result findSearch( @RequestBody Map searchMap){ return new Result(true,StatusCode.OK,"查詢成功",adminService.findSearch(searchMap)); } /** * 增加 * @param admin */ @ResponseBody @RequestMapping(method=RequestMethod.POST) public Result add(@RequestBody Admin admin ){ adminService.add(admin); return new Result(true,StatusCode.OK,"增加成功"); } /** * 修改 * @param admin */ @ResponseBody @RequestMapping(value="/{id}",method= RequestMethod.PUT) public Result update(@RequestBody Admin admin, @PathVariable Long id ){ admin.setId(id); adminService.update(admin); return new Result(true,StatusCode.OK,"修改成功"); } /** * 刪除 * @param id */ @ResponseBody @RequestMapping(value="/{id}",method= RequestMethod.DELETE) public Result delete(@PathVariable String id ){ adminService.deleteById(id); return new Result(true,StatusCode.OK,"刪除成功"); } /** * 管理員跳轉 * @return */ @RequestMapping(value = "/adminlogin") public String adminlogin() { return "admin/login/login"; } /** * admin登錄 * @param loginMap * @param request * @return */ @ResponseBody @RequestMapping(value="/login",method= RequestMethod.POST) public Result login(@RequestParam Map<String,String> loginMap,HttpServletRequest request){ Admin admin = adminService.finbyNameAndPassword(loginMap.get("name"),loginMap.get("password")); if (admin!=null){ request.getSession().setAttribute("admin",admin); Map map=new HashMap(); map.put("name",admin.getName()); return new Result(true,StatusCode.OK,"登錄成功"); }else { return new Result(false,StatusCode.ERROR,"賬號密碼錯誤"); } } /** * 管理員登錄成功 * @return */ @RequestMapping(value = "/index") public String success(){ return "admin/index"; } /** * 用戶列表 * @return */ @RequestMapping(value = "/userList") public String user(){ return "admin/usermanage/userList"; } @RequestMapping(value = "/echars") public String analysis(){ return "admin/echars/console"; } /** * 管理員退出登錄 * @return */ @RequestMapping(value = "/logout") public String logout(HttpSession session){ session.removeAttribute("admin"); return "admin/login/login"; } /** * 管理員修改密碼 * @return */ @ResponseBody @RequestMapping(value = "/passwd") public Result passwd(HttpSession session,String passwd,String oldpad){ Admin admindmin= (Admin) session.getAttribute("admin"); Admin admins=adminService.findById(admindmin.getId()); boolean old=encoder.matches(oldpad,admins.getPassword()); if (old){ String newPassd=encoder.encode(passwd); admins.setPassword(newPassd); adminService.update(admins); return new Result(true,StatusCode.OK,"成功"); }else { return new Result(false,StatusCode.ERROR,"更新失敗"); } } }
/** * 景點信息控制層 */ @Controller @CrossOrigin @RequestMapping("/travel") public class RecomTravelController { @Autowired private ScenicService scenicService; @Autowired private ScenicDao scenicDao; @Autowired private HotelService hotelService; @Autowired private HotelDao hotelDao; /** *查詢星級 * @return */ @ResponseBody @RequestMapping(value = "/star",method = RequestMethod.POST) public Result judgeStar(String id,String start){ System.out.println(id+"===="+start); Optional<Scenic> s = scenicDao.findById(id); if (s.isPresent()){ Scenic scenic = s.get(); int valuestar = (Integer.valueOf(start)+Integer.valueOf(scenic.getStart()))/2; scenic.setStart(valuestar); scenicDao.save(scenic); System.out.println("數據不為空!"); return new Result(true,1,"",""); }else { System.out.println("數據為空!"); return new Result(false,0,"",""); } } /** *查詢星級 * @return */ @ResponseBody @RequestMapping(value = "/hotel",method = RequestMethod.POST) public Result judgeHotelStar(Long id,String start){ Hotel scenic = hotelService.findById(id); if (scenic!=null){ int valuestar = (Integer.valueOf(start)+Integer.valueOf(scenic.getStar()))/2; scenic.setStar(valuestar); hotelDao.save(scenic); System.out.println("數據不為空!"); return new Result(true,1,"",""); }else { System.out.println("數據為空!"); return new Result(false,0,"",""); } } /** * 查詢單個景點 * @param model * @param id * @return */ @RequestMapping("/oneAttr") public String One_attr(Model model,Long id){ Scenic scenic=scenicService.findById(id); model.addAttribute("oneAttr",scenic); return "page/product"; } /** * 景點模糊查詢分頁 * @param model * @param start * @param limit * @param search_key * @return */ @RequestMapping("/search_attrs") public String search_attrs(Model model,@RequestParam(value = "start" ,defaultValue = "0")Integer start, @RequestParam(value = "limit" ,defaultValue = "6")Integer limit, @RequestParam String search_key){ start=start<0?0:start; Sort sort=new Sort(Sort.Direction.DESC,"id"); Pageable pageable=PageRequest.of(start,limit,sort); Specification specification=new Specification() { @Override public Predicate toPredicate(Root root, CriteriaQuery criteriaQuery, CriteriaBuilder criteriaBuilder) { List<Predicate> scenics=new ArrayList<>(); if (StringUtils.isNotBlank(search_key)){ scenics.add( criteriaBuilder.like(root.get("name"),"%"+search_key+"%")); } return criteriaBuilder.and(scenics.toArray(new Predicate[scenics.size()])); } }; Page<Scenic> page=scenicDao.findAll(specification,pageable); model.addAttribute("name",search_key); model.addAttribute("attrs",page); model.addAttribute("number",page.getNumber()); model.addAttribute("numberOfElements",page.getNumberOfElements()); model.addAttribute("size",page.getSize()); model.addAttribute("totalElements",page.getTotalElements()); model.addAttribute("totalPages",page.getTotalPages()); model.addAttribute("first",page.isFirst()); model.addAttribute("last",page.isLast()); return "page/travel"; } @RequestMapping("/local") public String localRefresh(Model model,Long id) { Scenic scenic=scenicService.findById(id); System.out.println(scenic.toString()); List<Hotel> hotels=hotelService.findByCountryLike(scenic.getContry()); Collections.sort(hotels, new Comparator<Hotel>() { @Override public int compare(Hotel o1, Hotel o2) { if (o1.getStar()<o2.getStar()){ return 2; } if (o1.getStar().equals(o2.getStar()) ){ return 1; } return -1; } }); if (hotels.size()>=4){ List newList=hotels.subList(0,3); model.addAttribute("scenics",newList); System.out.println("個數:"+newList.size()); }else { model.addAttribute("scenics",hotels); System.out.println("個數2:"+hotels.size()); } return "page/product::table_refresh"; } }
/** * 訂單控制器層 * */ @Controller @CrossOrigin @RequestMapping("/orders") public class OrdersController { @Autowired private OrdersService ordersService; @Autowired private HotelOrdersService hotel_ordersService; @Autowired private HotelService hotelService; @Autowired private ScenicService scenicService; /** * 查詢全部數據 * @return */ @ResponseBody @RequestMapping(value = "/list",method= RequestMethod.GET) public Result findAll(){ List<Orders> all = ordersService.findAll(); return new Result(true, StatusCode.OK,"查詢成功",all,all.size()); } /** * 查詢全部訂單 * @return */ @ResponseBody @RequestMapping(value = "/allorders",method = RequestMethod.POST) public String findAllOrders(HttpSession session, Model model) throws ParseException { User user= (User) session.getAttribute("user"); model.addAttribute("orders",ordersService.findOrders(user.getId().toString())); return "index_header::table_refresh"; } /** * 查詢全部訂單 * @return */ @ResponseBody @RequestMapping(value = "/allorder",method = RequestMethod.POST) public List<Orders> findAllOrder(HttpSession session) throws ParseException { User user= (User) session.getAttribute("user"); return ordersService.findOrders(user.getId().toString()); } /** * 查詢全部訂單 * @return */ @ResponseBody @RequestMapping(value = "/allorderhotel",method = RequestMethod.POST) public List<HotelOrders> findAllOrderHotel(HttpSession session){ User user= (User) session.getAttribute("user"); List<HotelOrders> hotel_orders=hotel_ordersService.hotel_orders(user.getId()); return hotel_orders; } /** * 根據ID查詢 * @param id ID * @return */ @ResponseBody @RequestMapping(value="/{id}",method= RequestMethod.GET) public Result findById(@PathVariable Long id){ return new Result(true,StatusCode.OK,"查詢成功",ordersService.findById(id)); } /** * 分頁+多條件查詢 * @param searchMap 查詢條件封裝 * @param page 頁碼 * @param size 頁大小 * @return 分頁結果 */ @ResponseBody @RequestMapping(value="/search/{page}/{size}",method=RequestMethod.POST) public Result findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){ Page<Orders> pageList = ordersService.findSearch(searchMap, page, size); return new Result(true,StatusCode.OK,"查詢成功", new PageResult<Orders>(pageList.getTotalElements(), pageList.getContent()) ); } /** * 根據條件查詢 * @param searchMap * @return */ @ResponseBody @RequestMapping(value="/search",method = RequestMethod.POST) public Result findSearch( @RequestBody Map searchMap){ return new Result(true,StatusCode.OK,"查詢成功",ordersService.findSearch(searchMap)); } /** * 訂單添加操作 * @param orders */ @ResponseBody @RequestMapping(value ="/add",method=RequestMethod.POST) public Result add(Orders orders, HttpSession session){ //獲取數量 User user = (User) session.getAttribute("user"); if (user == null){ return new Result(false,StatusCode.ACCESSERROR,"請登錄"); } return ordersService.add(orders,user.getId(),orders.getId(),orders.getQty()); } /** * 修改 * @param */ @ResponseBody @RequestMapping(value="/{id}",method= RequestMethod.PUT) public Result update(@PathVariable Long id){ ordersService.updateStatus(id); return new Result(true,StatusCode.OK,"修改成功"); } /** * 刪除 * @param id */ @ResponseBody @RequestMapping(value="/{id}",method= RequestMethod.DELETE) public Result delete(@PathVariable Long id ){ ordersService.deleteById(id); return new Result(true,StatusCode.OK,"刪除成功"); } @RequestMapping(value = "/ordersList") public String ordersList(){ return "admin/ordersmanage/orderslist"; } /** * 酒店評分 * @param hotel * @return */ @ResponseBody @PostMapping("/hotelOrderStar") public Result hotelOrderStar(Hotel hotel,@RequestParam("orderId")Long orderId){ Long id = hotel.getId(); Hotel newHotel = hotelService.findById(id); if(newHotel==null){ return new Result(false,StatusCode.ERROR,"未找到該酒店!"); } Integer currentStar = hotel.getStar(); Integer totalStar = newHotel.getStar(); if(currentStar<0){ return new Result(false,StatusCode.ERROR,"請選擇評分!"); } Integer commentCount = newHotel.getCommentCount(); commentCount=commentCount+1; totalStar=currentStar+totalStar; int avgStar = totalStar / commentCount; hotel.setCommentCount(commentCount); hotel.setStar(avgStar); Integer hotel1 = hotelService.updateStar(hotel); hotel_ordersService.updateStarStatus(orderId); if(hotel1==null){ return new Result(false,StatusCode.ERROR,"評分更新失敗!"); } return new Result(true,StatusCode.OK,"評價成功!"); } /** * 景點評分 * @param scenic * @return */ @ResponseBody @PostMapping("/travelOrderStar") public Result travelOrderStar(Scenic scenic,@RequestParam("orderId")Long orderId){ Long id = scenic.getId(); Scenic newScenic = scenicService.findById(id); if(newScenic==null){ return new Result(false,StatusCode.ERROR,"未找到該景點!"); } Integer totalStar = newScenic.getStart(); Integer currentStar = scenic.getStart(); if(currentStar<0){ return new Result(false,StatusCode.ERROR,"請選擇評分!"); } Integer commentCount = newScenic.getCommentCount(); commentCount=commentCount+1; totalStar=currentStar+totalStar; int avgStar = totalStar / commentCount; scenic.setCommentCount(commentCount); scenic.setStart(avgStar); Integer scenic1 = scenicService.updateStar(scenic); ordersService.updateStarStatus(orderId); if(scenic1==null){ return new Result(false,StatusCode.ERROR,"評分更新失敗!"); } return new Result(true,StatusCode.OK,"評價成功!"); } }
以上是“Java如何實現誠途旅游系統”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。