项目编号:BS-PT-031
本系统基于 Springboot开发,前台采用Bootstrap 实现,开发工具为IDEA/ECLIPSE,数据库为MYSQL,系统功能完整,运行无误,适合做毕业设计使用。
系统分为网站前台和后台管理:
前台系统可以进行用户注册登陆,查看预定酒店,查看预定景点线路,可以发布景点攻略等操作。
后台系统可以进行用户管理,景点管理,线路管理,攻略审核管理等操作。
下面就系统部分功能进行展示:
前端系统:
景区游玩线路
线路详情
我关注的线路
景区游玩攻略
发布攻略
酒店预定
景点预定
我的预定
后台管理系统
用户管理
酒店管理
景点管理
攻略管理
景点线路管理
以上就是基于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();
}
}