JavaWeb项目——旅游门户网站及后台管理系统

时间:2025-01-16 06:59:03
  • package ;
  • import .*;
  • import ;
  • import ;
  • import ;
  • import ;
  • import ;
  • import ;
  • import ;
  • import ;
  • import ;
  • import ;
  • @WebServlet("/hotel/*")
  • public class HotelServlet extends BaseServlet {
  • private final HotelService hotelService = new HotelServiceImpl();
  • private final ReserveService reserveService = new ReserveServiceImpl();
  • public void pageQuery(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  • //1.接受参数
  • String currentPageStr = ("currentPage");
  • String pageSizeStr = ("pageSize");
  • String cidStr = ("cid");
  • //接受rname 线路名称
  • String hname = ("hname");
  • hname = new String(("iso-8859-1"), "utf-8");
  • int cid = 0;//类别id
  • //2.处理参数
  • if (cidStr != null && () > 0 && !"null".equals(cidStr)) {
  • cid = (cidStr);
  • }
  • int currentPage = 0;//当前页码,如果不传递,则默认为第一页
  • if (currentPageStr != null && () > 0) {
  • currentPage = (currentPageStr);
  • } else {
  • currentPage = 1;
  • }
  • int pageSize = 0;//每页显示条数,如果不传递,默认每页显示5条记录
  • if (pageSizeStr != null && () > 0) {
  • pageSize = (pageSizeStr);
  • } else {
  • pageSize = 5;
  • }
  • //3. 调用service查询PageBean对象
  • PageBean<Hotel> pb = (cid, currentPage, pageSize, hname);
  • //4. 将pageBean对象序列化为json,返回
  • writeValue(pb, response);
  • }
  • public void findOne(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  • //1.接收id
  • String hid = ("hid");
  • //2.调用service查询route对象
  • Hotel hotel = (hid);
  • //3.转为json写回客户端
  • writeValue(hotel, response);
  • }
  • /**
  • * 判断当前登录用户是否预订过该酒店
  • *
  • * @param request
  • * @param response
  • * @throws ServletException
  • * @throws IOException
  • */
  • public void isReserve(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  • //1.获取线路id
  • String hid = ("hid");
  • //2.获取当前登录用户
  • User user = (User) ().getAttribute("user");
  • int uid; //用户id
  • if (user == null) {
  • //用户尚未登录
  • uid = 0;
  • } else {
  • //用户已经登录
  • uid = ();
  • }
  • //3.调用FavoriteService查询是否收藏
  • boolean flag = (hid, uid);
  • //4.写回客户端
  • writeValue(flag, response);
  • }
  • /**
  • * 添加预订
  • *
  • * @param request
  • * @param response
  • * @throws ServletException
  • * @throws IOException
  • */
  • public void addReserve(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  • //获取线路rid
  • String hid = ("hid");
  • //2.获取当前登录用户
  • User user = (User) ().getAttribute("user");
  • int uid; //用户id
  • if (user == null) {
  • //用户尚未登录
  • return;
  • } else {
  • //用户已经登录
  • uid = ();
  • }
  • //调用service添加
  • (hid, uid);
  • }
  • /**
  • * 分页查询当前登录用户预订的所有酒店
  • *
  • * @param request
  • * @param response
  • * @throws ServletException
  • * @throws IOException
  • */
  • public void findOrder(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  • //接收参数
  • String currentPageStr = ("currentPage");
  • String pageSizeStr = ("pageSize");
  • //获取当前登录用户
  • User user = (User) ().getAttribute("user");
  • int uid; //用户id
  • if (user == null) {
  • //用户尚未登录
  • return;
  • } else {
  • //用户已经登录
  • uid = ();
  • }
  • //处理参数
  • int currentPage = 1; //当前页码,如果不传递,则默认为第一页
  • if (currentPageStr != null && () > 0) {
  • currentPage = (currentPageStr);
  • }
  • int pageSize = 9; //每页显示条数,如果不传递,默认每页显示9条记录
  • if (pageSizeStr != null && () > 0) {
  • pageSize = (pageSizeStr);
  • }
  • //调用service查询所有收藏路线
  • PageBean<List<Object>> pb = (uid, currentPage, pageSize);
  • //将pageBean对象序列化为json,写回客户端
  • writeValue(pb, response);
  • }
  • /**
  • * 支付功能
  • *
  • * @param request
  • * @param response
  • * @throws ServletException
  • * @throws IOException
  • */
  • public void pay(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  • //获取订单号
  • String code = ("code");
  • (code);
  • }
  • }