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

embedded/2025/1/20 12:39:24/

项目介绍

在介绍文章之前呢,小伙伴们需要掌握关于咱们前后端知识点,我整理了几个课程,可以去学习:
课程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/embedded/155488.html

相关文章

面试-业务逻辑2

应用 给定2个数组a、b&#xff0c;若a[i] b[j]&#xff0c;则记(i,j)为一个二元数组&#xff0c;求具体的二元数组及其个数。 实现 a input("请输入数组a的元素个数&#xff1a;") # print(a) a_list list(map(int, input("请输入数组a的元素&#xff0c;…

25/1/15 嵌入式笔记 初学STM32F108

GPIO初始化函数 GPIO_Ini&#xff1a;初始化GPIO引脚的模式&#xff0c;速度和引脚号 GPIO_Init(GPIOA, &GPIO_InitStruct); // 初始化GPIOA的引脚0 GPIO输出控制函数 GPIO_SetBits&#xff1a;将指定的GPIO引脚设置为高电平 GPIO_SetBits(GPIOA, GPIO_Pin_0); // 将GPIO…

2025年1月19日(振动控制研究历史)

振动控制研究的历史可以追溯到19世纪末&#xff0c;随着工程和物理学的快速发展&#xff0c;特别是在机械、土木和航空工程领域。以下是振动控制研究历史的一些关键节点&#xff1a; 1. 早期阶段 (19世纪末 - 20世纪初) 在19世纪末&#xff0c;工程师开始注意到机械和建筑物的…

MyBatis动态SQL标签的案例

1. 使用<if>进行条件查询 假设我们有一个用户表users&#xff0c;包含字段id, name, age。我们要根据名字和年龄来查找用户&#xff0c;但这两个条件都是可选的。 <select id"findUsers" parameterType"map" resultType"User">SEL…

今天你学C++了吗?——C++中的STL

♥♥♥~~~~~~欢迎光临知星小度博客空间~~~~~~♥♥♥ ♥♥♥零星地变得优秀~也能拼凑出星河~♥♥♥ ♥♥♥我们一起努力成为更好的自己~♥♥♥ ♥♥♥如果这一篇博客对你有帮助~别忘了点赞分享哦~♥♥♥ ♥♥♥如果有什么问题可以评论区留言或者私信我哦~♥♥♥ ✨✨✨✨✨✨ 个…

嵌入式知识点总结(一)-C/C++关键字

针对于嵌入式软件杂乱的知识点总结起来&#xff0c;提供给读者学习复习对下述内容的强化。 目录 1.C语言宏中"#“和"##"的用法 1.1.(#)字符串化操作符 1.2.(##)符号连接操作符 2.关键字volatile有什么含意?并举出三个不同的例子? 2.1.并行设备的硬件寄存…

JavaScript 代码规范

JavaScript 代码规范 1. 引言 JavaScript 是一种广泛使用的编程语言,尤其在网页开发中占据重要地位。为了确保代码的质量、可读性和可维护性,遵循一套统一的代码规范至关重要。本规范旨在为 JavaScript 开发者提供一个清晰、一致的编码标准,以促进团队合作和代码共享。 2…

RocketMQ中的一些细节

1.前言 此文章是在儒猿课程中的学习笔记&#xff0c;感兴趣的想看原来的课程可以去咨询儒猿课堂《从0开始带你成为RocketMQ高手》&#xff0c;我本人觉得这个作者还是不错&#xff0c;都是从场景来进行分析&#xff0c;感觉还是挺适合我这种小白的。这块主要都是我自己的学习笔…