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

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

项目编号:BS-PT-031

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

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

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

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

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

前端系统:


image.png

线路详情

image.png

我关注的线路

image.png

景区游玩攻略

image.png

发布攻略

image.png

酒店预定

image.png

景点预定

image.png

我的预定

image.png

后台管理系统


用户管理

image.png

酒店管理

image.png

景点管理

image.png

攻略管理

image.png

景点线路管理

image.png

以上就是基于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 {
    @Autowired
    private 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())) {
               //如果密码一致,登陆成功
                //将用户名存入Cookie
                Cookie 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 {
    @Autowired
    private HotelRepository hotelRepository;
    @Autowired
    private AttractionsRepository attractionsRepository;
    @Autowired
    private UserRepository userRepository;
    @Autowired
    private UserHotelRepository userHotelRepository;
    @Autowired
    private 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 {
    @Autowired
    private TravelRouteRepository travelRouteRepository;
    @Autowired
    private UserRepository userRepository;
    @Autowired
    private 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();
    }
}
相关文章
|
3月前
|
JavaScript 前端开发 Java
基于springboot的留守儿童爱心网站
这是一个基于SpringBoot的留守儿童爱心网站,包含管理员和用户两种角色。管理员负责用户、新闻、志愿活动、捐赠等管理;用户可进行登录注册、爱心捐赠及活动报名。项目采用SpringBoot与Mybatis作为后端框架,前端则使用HTML和VUE。适用于JDK1.8、IDEA/Eclipse、MySQL5.7/8.x,无需特定Tomcat或Maven版本,支持Windows系统。
97 13
基于springboot的留守儿童爱心网站
|
4月前
|
安全 前端开发 Java
Web端系统开发解决跨域问题——以Java SpringBoot框架配置Cors为例
在Web安全上下文中,源(Origin)是指一个URL的协议、域名和端口号的组合。这三个部分共同定义了资源的来源,浏览器会根据这些信息来判断两个资源是否属于同一源。例如,https://www.example.com:443和http://www.example.com虽然域名相同,但由于协议和端口号不同,它们被视为不同的源。同源(Same-Origin)是指两个URL的协议、域名和端口号完全相同。只有当这些条件都满足时,浏览器才认为这两个资源来自同一源,从而允许它们之间的交互操作。
Web端系统开发解决跨域问题——以Java SpringBoot框架配置Cors为例
|
5月前
|
JavaScript Java 测试技术
基于SpringBoot+Vue+uniapp的旅游攻略系统的详细设计和实现(源码+lw+部署文档+讲解等)
基于SpringBoot+Vue+uniapp的旅游攻略系统的详细设计和实现(源码+lw+部署文档+讲解等)
122 7
|
5月前
|
JavaScript Java 测试技术
基于SpringBoot+Vue+uniapp的二手商品网站的详细设计和实现(源码+lw+部署文档+讲解等)
基于SpringBoot+Vue+uniapp的二手商品网站的详细设计和实现(源码+lw+部署文档+讲解等)
|
5月前
|
JavaScript Java 测试技术
基于SpringBoot+Vue+uniapp的粤港澳大湾区旅游系统的详细设计和实现(源码+lw+部署文档+讲解等)
基于SpringBoot+Vue+uniapp的粤港澳大湾区旅游系统的详细设计和实现(源码+lw+部署文档+讲解等)
|
5月前
|
JavaScript Java 测试技术
基于SpringBoot+Vue+uniapp的个人健康管理网站的详细设计和实现(源码+lw+部署文档+讲解等)
基于SpringBoot+Vue+uniapp的个人健康管理网站的详细设计和实现(源码+lw+部署文档+讲解等)
|
5月前
|
JavaScript Java 测试技术
基于SpringBoot+Vue+uniapp的“力炫”健身馆网站的详细设计和实现(源码+lw+部署文档+讲解等)
基于SpringBoot+Vue+uniapp的“力炫”健身馆网站的详细设计和实现(源码+lw+部署文档+讲解等)
|
5月前
|
JavaScript Java 测试技术
基于springboot+vue.js+uniapp的在线音乐网站附带文章源码部署视频讲解等
基于springboot+vue.js+uniapp的在线音乐网站附带文章源码部署视频讲解等
68 2
|
5月前
|
JavaScript Java 测试技术
基于SpringBoot+Vue+uniapp的国风彩妆网站的详细设计和实现(源码+lw+部署文档+讲解等)
基于SpringBoot+Vue+uniapp的国风彩妆网站的详细设计和实现(源码+lw+部署文档+讲解等)
|
5月前
|
JavaScript Java 测试技术
基于SpringBoot+Vue+uniapp的古风生活体验交流网站的详细设计和实现(源码+lw+部署文档+讲解等)
基于SpringBoot+Vue+uniapp的古风生活体验交流网站的详细设计和实现(源码+lw+部署文档+讲解等)

热门文章

最新文章