基于Springboot实现旅游网站系统开发

devtools/2025/1/21 4:54:57/

项目介绍

在介绍文章之前呢,小伙伴们需要掌握关于咱们前后端知识点,我整理了几个课程,可以去学习:
课程1-java和vue前后端分离项目实战
课程2-HTML5入门级开发
课程3-vue入门级开发教程
课程4-CSS入门级开发
里边的老师也很敬业,可以进行自己的薄弱点进行学习
好了咱们言归正传!

本系统基于 Springboot开发,前台采用Bootstrap 实现,开发工具为IDEA/ECLIPSE,数据库为MYSQL,系统功能完整,运行无误,适合做毕业设计使用。

系统分为网站前台和后台管理:

前台系统可以进行用户注册登陆,查看预定酒店,查看预定景点线路,可以发布景点攻略等操作。

后台系统可以进行用户管理,景点管理,线路管理,攻略审核管理等操作。

下面就系统部分功能进行展示:

前端系统:

desc
景区游玩线路

desc
线路详情

desc
我关注的线路

desc
景区游玩攻略

desc
发布攻略

desc
酒店预定

desc
景点预定

desc
我的预定

desc

后台管理系统

用户管理
文章链接

desc
酒店管理

desc
景点管理

desc
攻略管理

desc
景点线路管理

desc
以上就是基于Springboot实现的旅游网站管理系统的部分功能,本系统功能结构完整,层次结构清晰,方便进行修改和完善。

部分实现代码:

package com.power.travel.service;import com.power.travel.core.Result;
import com.power.travel.core.ResultGenerator;
import com.power.travel.model.User;
import com.power.travel.util.CookieUitl;
import com.power.travel.util.IdGenerator;
import com.power.travel.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;@Service
public class LoginService {@Autowiredprivate UserRepository userRepository;/**** @param user  登陆用户名和密码的数据封装* @param response* @return*/public Result login(User user, HttpServletResponse response) {//调用JPA的的接口来查询数据库:根据用户名来查询User userByUsername = userRepository.findUserByUsername(user.getUsername());if (userByUsername == null) {return ResultGenerator.genFailResult("用户名错误!");} else {//如果根据用户名能查到数据:再比对密码if (user.getPassword().equals(userByUsername.getPassword())) {//如果密码一致,登陆成功//将用户名存入CookieCookie cookie = new Cookie("username", user.getUsername());cookie.setPath("/");cookie.setMaxAge(3600);response.addCookie(cookie);return ResultGenerator.genSuccessResult();} else {//登陆失败return ResultGenerator.genFailResult("密码错误!");}}}public void logout(HttpServletRequest request, HttpServletResponse response) {Cookie cookie = CookieUitl.get(request, "username");if(cookie != null){CookieUitl.set(response,"username",null,0);}//        String value = null;
//
//        Cookie[] cookies = request.getCookies();
//        if (cookies == null){
//            System.out.println("error");
//        }else{
//            for (int i = 0;i<cookies.length;i++){
//                if(cookies[i].getName().equals("root")){
//                    value = cookies[i].getValue();
//                }
//            }
//        }
//
//        Cookie cookie = new Cookie("username",value);
//        cookie.setMaxAge(-1);}public Result register(User user) {//查询用户名是否存在User userByUsername = userRepository.findUserByUsername(user.getUsername());if(userByUsername != null){return ResultGenerator.genFailResult("用户名重复!");}//Todo 这里有一个事务操作user.setId(IdGenerator.id());userRepository.save(user);return ResultGenerator.genSuccessResult();}
}
package com.power.travel.service;import com.power.travel.core.Result;
import com.power.travel.core.ResultGenerator;
import com.power.travel.core.ServiceException;
import com.power.travel.model.*;
import com.power.travel.repository.*;
import com.power.travel.util.CookieUitl;
import com.power.travel.util.IdGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.thymeleaf.util.StringUtils;import javax.persistence.criteria.Predicate;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;@Service
public class ReserveService {@Autowiredprivate HotelRepository hotelRepository;@Autowiredprivate AttractionsRepository attractionsRepository;@Autowiredprivate UserRepository userRepository;@Autowiredprivate UserHotelRepository userHotelRepository;@Autowiredprivate UserAttractionsRepository userAttractionsRepository;public Page<Hotel> reserveHotelListUI(String searchName, Pageable pageable) {//查询启用的酒店列表Page<Hotel> hotelPage = hotelRepository.findAll((root, query, cb) -> {List<Predicate> predicates = new ArrayList<>();//status状态,查询状态为0,启动的酒店predicates.add((cb.equal(root.get("status"), 0)));//酒店name模糊查询if (!StringUtils.isEmpty(searchName)) {predicates.add((cb.like(root.get("name"), "%" + searchName + "%")));}query.where(predicates.toArray(new Predicate[]{}));query.orderBy(cb.desc(root.get("createDate")));return null;}, pageable);return hotelPage;}public Hotel findHotelById(String id) {return hotelRepository.findById(id).orElseThrow(() -> new ServiceException("酒店id错误!"));}public Page<Attractions> reserveAttractionsListUI(String searchName, Pageable pageable) {//查询启用的景点列表Page<Attractions> attractionsPage = attractionsRepository.findAll((root, query, cb) -> {List<Predicate> predicates = new ArrayList<>();//status状态,查询状态为0,启动的景点predicates.add((cb.equal(root.get("status"), 0)));//景点name模糊查询if (!StringUtils.isEmpty(searchName)) {predicates.add((cb.like(root.get("name"), "%" + searchName + "%")));}query.where(predicates.toArray(new Predicate[]{}));query.orderBy(cb.desc(root.get("createDate")));return null;}, pageable);return attractionsPage;}public Attractions findAttractionsById(String id) {return attractionsRepository.findById(id).orElseThrow(() -> new ServiceException("景点id错误!"));}public List<UserHotel> getReserveHotelByUser(HttpServletRequest request) {Cookie cookie = CookieUitl.get(request, "username");if (cookie == null) {throw new ServiceException("未能获得正确的用户名");}User user = userRepository.findUserByUsername(cookie.getValue());return userHotelRepository.findUserHotelsByUser(user);}@Transactional(rollbackFor = Exception.class)public Result cancelReserve(HttpServletRequest request, String id) {Cookie cookie = CookieUitl.get(request, "username");if (cookie == null) {throw new ServiceException("用户没有登录!");}Hotel hotel = findHotelById(id);User user = userRepository.findUserByUsername(cookie.getValue());UserHotel userHotel = userHotelRepository.findUserHotelByHotelAndUser(hotel, user);//存在值就是取消预约.不存在值就是预约if (userHotel != null) {userHotelRepository.delete(userHotel);} else {UserHotel newUserHotel = new UserHotel();newUserHotel.setId(IdGenerator.id());newUserHotel.setCreateDate(new Date());newUserHotel.setUser(user);newUserHotel.setHotel(hotel);userHotelRepository.saveAndFlush(newUserHotel);}return ResultGenerator.genSuccessResult();}public Boolean isReserveHotel(HttpServletRequest request, String id) {Cookie cookie = CookieUitl.get(request, "username");if (cookie != null) {User user = userRepository.findUserByUsername(cookie.getValue());Hotel hotel = findHotelById(id);UserHotel userHotel = userHotelRepository.findUserHotelByHotelAndUser(hotel, user);//每个酒店只能预约一次if (userHotel != null) {return true;}}return false;}public List<UserAttractions> getReserveAttractionsByUser(HttpServletRequest request) {Cookie cookie = CookieUitl.get(request, "username");if (cookie == null) {throw new ServiceException("未能获得正确的用户名");}User user = userRepository.findUserByUsername(cookie.getValue());return userAttractionsRepository.findUserAttractionsByUser(user);}@Transactional(rollbackFor = Exception.class)public Result cancelAttractionsReserve(HttpServletRequest request, String id) {Cookie cookie = CookieUitl.get(request, "username");if (cookie == null) {throw new ServiceException("用户没有登录!");}Attractions attractions = findAttractionsById(id);User user = userRepository.findUserByUsername(cookie.getValue());UserAttractions userAttractions = userAttractionsRepository.findUserAttractionsByAttractionsAndUser(attractions, user);//存在值就是取消预约.不存在值就是预约if (userAttractions != null) {userAttractionsRepository.delete(userAttractions);} else {UserAttractions newUserAttractions = new UserAttractions();newUserAttractions.setId(IdGenerator.id());newUserAttractions.setCreateDate(new Date());newUserAttractions.setUser(user);newUserAttractions.setAttractions(attractions);userAttractionsRepository.saveAndFlush(newUserAttractions);}return ResultGenerator.genSuccessResult();}public Boolean isReserveAttractions(HttpServletRequest request, String id) {Cookie cookie = CookieUitl.get(request, "username");if (cookie != null) {User user = userRepository.findUserByUsername(cookie.getValue());Attractions attractions = findAttractionsById(id);UserAttractions userAttractions = userAttractionsRepository.findUserAttractionsByAttractionsAndUser(attractions, user);//每个景点只能预约一次if (userAttractions != null) {return true;}}return false;}public List<Hotel> getTop10Hotel() {PageRequest pageable = PageRequest.of(0, 10);//查询启用的酒店列表Page<Hotel> hotelPage = hotelRepository.findAll((root, query, cb) -> {List<Predicate> predicates = new ArrayList<>();//status状态,查询状态为0,启动的酒店predicates.add((cb.equal(root.get("status"), 0)));query.where(predicates.toArray(new Predicate[]{}));query.orderBy(cb.desc(root.get("createDate")));return null;}, pageable);return hotelPage.getContent();}public List<Attractions> getTop10Attractions() {PageRequest pageable = PageRequest.of(0, 10);Page<Attractions> attractionsPage = attractionsRepository.findAll((root, query, cb) -> {List<Predicate> predicates = new ArrayList<>();//status状态,查询状态为0,启动的景点predicates.add((cb.equal(root.get("status"), 0)));//景点name模糊查询query.where(predicates.toArray(new Predicate[]{}));query.orderBy(cb.desc(root.get("createDate")));return null;}, pageable);return attractionsPage.getContent();}
}
package com.power.travel.service;import com.power.travel.core.Result;
import com.power.travel.core.ResultGenerator;
import com.power.travel.core.ServiceException;
import com.power.travel.model.TravelRoute;
import com.power.travel.model.User;
import com.power.travel.model.UserRoute;
import com.power.travel.repository.TravelRouteRepository;
import com.power.travel.repository.UserRepository;
import com.power.travel.repository.UserRouteRepository;
import com.power.travel.util.CookieUitl;
import com.power.travel.util.IdGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.thymeleaf.util.StringUtils;import javax.persistence.criteria.Predicate;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;@Service
public class RouteService {@Autowiredprivate TravelRouteRepository travelRouteRepository;@Autowiredprivate UserRepository userRepository;@Autowiredprivate UserRouteRepository userRouteRepository;public Page<TravelRoute> TravelRouteListUI(String searchName, Pageable pageable) {//查询启用的景区游玩路线列表Page<TravelRoute> travelRoutePage = travelRouteRepository.findAll((root, query, cb) -> {List<Predicate> predicates = new ArrayList<>();//status状态,查询状态为0,启动的路线predicates.add((cb.equal(root.get("status"), 0)));//景区游玩路线name模糊查询if (!StringUtils.isEmpty(searchName)) {predicates.add((cb.like(root.get("name"), "%" + searchName + "%")));}query.where(predicates.toArray(new Predicate[]{}));query.orderBy(cb.desc(root.get("createDate")));return null;}, pageable);return travelRoutePage;}public TravelRoute findTravelRouteById(String id) {return travelRouteRepository.findById(id).orElseThrow(() -> new ServiceException("路线id错误!"));}public Boolean isRoute(HttpServletRequest request, String id) {Cookie cookie = CookieUitl.get(request, "username");if (cookie != null) {User user = userRepository.findUserByUsername(cookie.getValue());TravelRoute travelRoute = findTravelRouteById(id);UserRoute userRoute = userRouteRepository.findUserRouteByTravelRouteAndUser(travelRoute, user);//每个路线只能关注一次if (userRoute != null) {return true;}}return false;}public List<UserRoute> getTravelRouteByUser(HttpServletRequest request) {Cookie cookie = CookieUitl.get(request, "username");if (cookie == null) {throw new ServiceException("未能获得正确的用户名");}User user = userRepository.findUserByUsername(cookie.getValue());return userRouteRepository.findUserRouteByUser(user);}@Transactional(rollbackFor = Exception.class)public Result cancelTravelRouteReserve(HttpServletRequest request, String id) {Cookie cookie = CookieUitl.get(request, "username");if (cookie == null) {throw new ServiceException("用户没有登录!");}TravelRoute travelRoute = findTravelRouteById(id);User user = userRepository.findUserByUsername(cookie.getValue());UserRoute userRoute = userRouteRepository.findUserRouteByTravelRouteAndUser(travelRoute, user);//存在值就是取消预约.不存在值就是预约if (userRoute != null) {userRouteRepository.delete(userRoute);} else {UserRoute newUserRoute = new UserRoute();newUserRoute.setId(IdGenerator.id());newUserRoute.setCreateDate(new Date());newUserRoute.setUser(user);newUserRoute.setTravelRoute(travelRoute);userRouteRepository.saveAndFlush(newUserRoute);}return ResultGenerator.genSuccessResult();}public List<TravelRoute> findTop10Route() {PageRequest pageable = PageRequest.of(0, 10);//查询启用的景区游玩路线列表Page<TravelRoute> travelRoutePage = travelRouteRepository.findAll((root, query, cb) -> {List<Predicate> predicates = new ArrayList<>();//status状态,查询状态为0,启动的路线predicates.add((cb.equal(root.get("status"), 0)));query.where(predicates.toArray(new Predicate[]{}));query.orderBy(cb.desc(root.get("createDate")));return null;}, pageable);return travelRoutePage.getContent();}
}

http://www.ppmy.cn/devtools/152265.html

相关文章

CV 图像处理基础笔记大全(超全版哦~)!!!

一、图像的数字化表示 像素 数字图像由众多像素组成&#xff0c;是图像的基本构成单位。在灰度图像中&#xff0c;一个像素用一个数值表示其亮度&#xff0c;通常 8 位存储&#xff0c;取值范围 0 - 255&#xff0c;0 为纯黑&#xff0c;255 为纯白。例如&#xff0c;一幅简单的…

Django框架:python web开发

1.环境搭建&#xff1a; &#xff08;a&#xff09;开发环境&#xff1a;pycharm &#xff08;b&#xff09;虚拟环境&#xff08;可有可无&#xff0c;优点&#xff1a;使用虚拟环境可以把使用的包自动生成一个文件&#xff0c;其他人需要使用时可以直接选择导入包&#xff…

SpringBoot整合junit

SpringBoot 整合 junit 特别简单&#xff0c;分为以下三步完成: 1在测试类上添加 SpringBootTest 注解2使用 Autowired 注入要测试的资源3定义测试方法进行测试 1.实验准备&#xff1a; 创建一个名为 springboot_junit_test 的 SpringBoot 工程&#xff0c;工程目录结构如下…

如何修改React 项目版本

npx create-react-app react-project-name在项目根目录运行以下命令&#xff0c;卸载当前的 React 和 React-DOM&#xff1a; npm uninstall react react-dom重新安装 React 和 React-DOM 指定版本&#xff1a; npm install react18.2.0 react-dom18.2.0确认 package.json 中…

SDL2:arm64下编译使用 -- SDL2多媒体库使用音频实例

更多内容&#xff1a;XiaoJ的知识星球 SDL2&#xff1a;Android-arm64端编译使用 2. SDL2&#xff1a;Android-arm64端编译使用2.1 安装和配置NDK2.2 下载编译SDL22.3 SDL2使用示例&#xff1a;Audio2.4 Android设备运行 2. SDL2&#xff1a;Android-arm64端编译使用 在Linux系…

Android-Gradle-自动化多渠道打包

所谓自动执行加固&#xff0c;无非就是几行命令&#xff0c;360加固保提供了一套命令行进行加固 特别提醒&#xff0c;此处360配置可选项的增强服务有bug&#xff0c;已经跟官方沟通&#xff0c;他们需要在下个版本修复&#xff0c;当前存在bug的版本3.2.2.3&#xff08;2020-0…

《初始Linux:多平台兼容的强者,无缝衔接各类设备的桥梁 》

对于新手而言&#xff0c;Linux 虽然看似神秘&#xff0c;但只要迈出第一步&#xff0c;你会发现它其实充满了乐趣和挑战。在接下来的内容中&#xff0c;我将带你一步步揭开 Linux 的神秘面纱&#xff0c;从基础概念到实际操作&#xff0c;帮助你轻松入门&#xff0c;开启属于你…

FastAPI 应用的容器化与 Docker 部署:提升性能与可扩展性

FastAPI 应用的容器化与 Docker 部署&#xff1a;提升性能与可扩展性 目录 &#x1f433; 使用 Docker 容器化 FastAPI 应用⚙️ 使用 Docker Compose 管理多个服务的部署&#x1f680; 在 Docker 容器中部署与运行 FastAPI 应用 1. &#x1f433; 使用 Docker 容器化 FastAPI…