Java项目:在线旅游订票系统(java+SpringBoot+FreeMarker+Mysql)

实现的功能有:

管理员:系统管理、出发点管理、攻略分类管理、攻略管理、旅游景点产品管理、旅游景点产品详情管理、景点产品评论管理、定制信息管理、景点门票管理、旅游行程管理、景点评分管理、主题管理、新闻管理、订单统计等。

普通用户:注册登录、个人信息管理(个人信息、密码、订单等)、查看新闻、收藏景点产品、预定旅游景点、个人充值、预定景点门票、增加个人定制等。

Java项目:在线旅游订票系统(java+SpringBoot+FreeMarker+Mysql)_第1张图片

Java项目:在线旅游订票系统(java+SpringBoot+FreeMarker+Mysql)_第2张图片

 Java项目:在线旅游订票系统(java+SpringBoot+FreeMarker+Mysql)_第3张图片

 Java项目:在线旅游订票系统(java+SpringBoot+FreeMarker+Mysql)_第4张图片

 Java项目:在线旅游订票系统(java+SpringBoot+FreeMarker+Mysql)_第5张图片

景点商家信息代码: 

/**
 * @Description: TODO(景点商家信息)
 */
@Controller
@RequestMapping("/sellers")
public class SellerController {

    @Autowired
    private ISellerService iSellerService;

    @Autowired
    private IUserService iUserService;

    @RequestMapping("/findBySid.do")
    @PreAuthorize("hasAnyAuthority('/sellers/findBySid.do')")
    public ModelAndView findBySid(Integer sid) throws Exception {
        ModelAndView mv = new ModelAndView();
        Seller seller = iSellerService.findBySid(sid);
        mv.addObject("sellerInfo",seller);
        List list = iUserService.findAll(1,1000,"%%");
        mv.addObject("UList",list);
        mv.setViewName("seller-update");
        return mv;
    }

    @RequestMapping("/findUsers.do")
    @PreAuthorize("hasAnyAuthority('/sellers/findUsers.do')")
    public ModelAndView findUsers() throws Exception{
        List list = iSellerService.findUsers();
        ModelAndView mv = new ModelAndView();
        mv.addObject("users",list);
        mv.setViewName("seller-add");
        return mv;
    }
    //新增商家
    @RequestMapping("/save.do")
    @PreAuthorize("hasAnyAuthority('/sellers/save.do')")
    public String save(Seller seller) throws Exception{
        iSellerService.save(seller);
        return "redirect:findAlls.do";
    }

    //查询所有商家
    @RequestMapping("/findAlls.do")
    @PreAuthorize("hasAnyAuthority('/sellers/findAlls.do')")
    public ModelAndView findAlls(
        @RequestParam(name="page",required = true, defaultValue = "1") Integer page,
        @RequestParam(name="size",required = true, defaultValue = "10") Integer size,
        @RequestParam(name="search",required = true, defaultValue = "") String search
    )throws Exception{
        ModelAndView mv = new ModelAndView();
        List list = iSellerService.findAlls(page,size,"%"+search+"%");
        PageInfo pageInfo = new PageInfo(list);
        mv.addObject("pageInfo",pageInfo);
        mv.setViewName("seller-list");
        return mv;
    }

    //删除商家
    @RequestMapping("/delete.do")
    @PreAuthorize("hasAnyAuthority('/sellers/delete.do')")
    public String delete(Integer sid) throws Exception{
        iSellerService.delete(sid);
        return "redirect:findAlls.do";
    }

    //修改商家
    @RequestMapping("/update.do")
    @PreAuthorize("hasAnyAuthority('/sellers/update.do')")
    public String update(Seller seller) throws Exception{
        iSellerService.update(seller);
        return "redirect:findAlls.do";
    }
}

用户登录服务类:

/**
 * @Description: TODO(注册、登录、退出)
 */
@WebServlet("/user/*")
public class UserServlet extends BaseServlet {
    //声明UserService业务对象
    private IUserService service = new UserServiceImpl();

    /**
     * 校验验证码
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public boolean checkCodeMethod(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String check = request.getParameter("check");
        //从sesion中获取验证码
        HttpSession session = request.getSession();
        String checkcode_server = (String)session.getAttribute("CHECKCODE_SERVER");
        session.removeAttribute("CHECKCODE_SERVER");//为了保证验证码只能使用一次

        if(checkcode_server == null || !checkcode_server.equalsIgnoreCase(check)){
            ResultInfo info = new ResultInfo();
            //验证码错误
            if ("".equals(check)){
                info.setErrorMsg("验证码不能为空");
            }else{
                info.setErrorMsg("验证码错误");
            }
            info.setFlag(false);
            //将info对象序列化为json,响应数据
            response.setContentType("application/json;charset=utf-8");
            String json = writeValueAsString(info);
            response.getWriter().write(json);
            return false;
        }
        return true;
    }
    /**
     * 注册功能
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void regist(HttpServletRequest request, HttpServletResponse response) throws Exception {
        //验证码
        if(!checkCodeMethod(request,response)){
            return;
        }

        //1.获取数据,封装对象
        Map map = request.getParameterMap();
        User user = new User();
        try {
            BeanUtils.populate(user,map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //2.调用service完成注册
        boolean flag = false;
        if (user.getUsername() != null){
            flag = service.regist(user);
        }
        ResultInfo info = new ResultInfo();
        if(flag){//注册成功
            info.setFlag(true);
        }else {//注册失败
            info.setFlag(false);
            info.setErrorMsg("用户名已存在!");
        }

        //3.将info对象序列化为json,响应数据
        String json = writeValueAsString(info);
        response.setContentType("application/json;charset=utf-8");
        response.getWriter().write(json);
    }

    /**
     * 登录功能
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void login(HttpServletRequest request, HttpServletResponse response) throws Exception {
        //1.获取用户名和密码数据
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String remember = request.getParameter("remember");

        username = username != null ? username : "";
        password = password != null ? password : "";
        remember = remember != null ? remember : "";

        User user = new User();
        user.setUsername(username);
        user.setPassword(password);
        //3.调用Service查询
        User u  = service.login(user);
        ResultInfo info = new ResultInfo();

        //4.判断用户对象是否为null
        if(u == null){
            //用户名密码或错误
            info.setFlag(false);
            info.setErrorMsg("用户名密码或错误");
        }
        //5.判断登录成功
        if(u != null){
            Cookie user_cookie = new Cookie("username",  URLEncoder.encode(username, "UTF-8")); //解决cookie乱码
            Cookie pswd_cookie = new Cookie("password", password);
            Cookie reme_cookie = new Cookie("remember", remember);
            if(remember.equals("1")) {
                user_cookie.setMaxAge(24*60*60);
                user_cookie.setPath(request.getContextPath()+"/");
                response.addCookie(user_cookie);

                pswd_cookie.setMaxAge(24*60*60);
                pswd_cookie.setPath(request.getContextPath()+"/");
                response.addCookie(pswd_cookie);

                reme_cookie.setMaxAge(24*60*60);
                reme_cookie.setPath(request.getContextPath()+"/");
                response.addCookie(reme_cookie);
            }else {
                user_cookie.setMaxAge(0);
                user_cookie.setPath("/");
                response.addCookie(user_cookie);
                pswd_cookie.setMaxAge(0);
                pswd_cookie.setPath("/");
                response.addCookie(pswd_cookie);
                reme_cookie.setMaxAge(0);
                reme_cookie.setPath("/");
                response.addCookie(reme_cookie);
            }
            if (!checkCodeMethod(request,response)){
                return;
            }
            request.getSession().setAttribute("user",u);//登录成功标记
            //登录成功
            info.setFlag(true);
        }
        //响应数据
       writeValue(info,response);
    }

    /**
     * 查询一个
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void findOne(HttpServletRequest request, HttpServletResponse response) throws IOException {
        //从session中获取登录用户
        Object user = request.getSession().getAttribute("user");
        //将user写回客户端
        writeValue(user,response);
    }

    /**
     * 退出功能
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void exit(HttpServletRequest request, HttpServletResponse response) throws IOException {
        //1.销毁session
        request.getSession().invalidate();
        //2.跳转登录页面
        response.sendRedirect(request.getContextPath()+"/login.jsp");
    }
}

酒店订单相关操作:

/**
 * @Description: TODO(酒店订单相关操作)
 */
@WebServlet("/order/*")
public class OrderServlet extends BaseServlet {

    /**
     * 新增线路订单
     * @param request
     * @param response
     * @throws Exception
     */
    public void OrderRoute(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ResultInfo info = new ResultInfo();

        IOrderService IOrderService = new OrderServiceImpl();

        //1.获取参数
        Map map = request.getParameterMap();
        if (map.size()==0 || map.size()!=9){
            info.setFlag(false);
            info.setErrorMsg("预定失败");
            String json = writeValueAsString(info);
            response.setContentType("application/json;charset=utf-8");
            response.getWriter().write(json);
            return;
        }

        //2.1满足预定条件,查询账户余额
        String uid = map.get("uid")[0];
        String sid = map.get("sid")[0];
//        Account account = IOrderService.findAccount(Integer.parseInt(uid));
        Double paymoney = Double.valueOf(map.get("paymoney")[0]);
//        if (account.getMoney()< paymoney){
//            info.setFlag(false);
//            info.setErrorMsg("您的账户余额不足,请充值!");
//            String json = writeValueAsString(info);
//            response.setContentType("application/json;charset=utf-8");
//            response.getWriter().write(json);
//            return;
//        }

        //2.2余额可以进行预定,进行转账
//        int target = IOrderService.findBySid(Integer.parseInt(sid));
//        IOrderService.transfer(Integer.parseInt(uid),target,paymoney);

        //2.3转账成功,生成订单,封装对象
        RouteOrder routeOrder = new RouteOrder();
        try {
            BeanUtils.populate(routeOrder,map);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        //生成订单号
        routeOrder.setOrderId(UuidUtil.getUuid());

        //下单时间
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String dateTime = LocalDateTime.now().format(formatter);
        routeOrder.setOrdertime(dateTime);

        //3.调用订单方法
        IOrderService.addROrder(routeOrder);

        //4.响应结果
        info.setFlag(true);
        writeValue(info,response);
    }
    /**
     * 新增酒店订单
     * @param request
     * @param response
     * @throws IOException
     */
    public void addOrder(HttpServletRequest request, HttpServletResponse response) throws Exception {

        ResultInfo info = new ResultInfo();

        IOrderService IOrderService = new OrderServiceImpl();

        //1.获取参数
        Map map = request.getParameterMap();
        if (map.size()==0 || map.size()!=11){
            info.setFlag(false);
            info.setErrorMsg("预定失败");
            String json = writeValueAsString(info);
            response.setContentType("application/json;charset=utf-8");
            response.getWriter().write(json);
            return;
        }

        //2.查询入住酒店和日期,判断是否可以入住
        String uid = map.get("uid")[0];
        String hid = map.get("hid")[0];
        String beginday = map.get("beginday")[0];
        String endday = map.get("endday")[0];
        //2.1调用service方法查询
        int count= IOrderService.selectOrder(uid,hid,beginday,endday,beginday,endday);
        if (count!=0){//已经存在预定
            info.setFlag(false);
            info.setErrorMsg("您在该时间内已预定!");
            String json = writeValueAsString(info);
            response.setContentType("application/json;charset=utf-8");
            response.getWriter().write(json);
            return;
        }

        //2.2满足预定条件,查询账户余额
//        Account account = IOrderService.findAccount(Integer.parseInt(uid));
        Double paymoney = Double.valueOf(map.get("paymoney")[0]);
//        if (account.getMoney()< paymoney){
//            info.setFlag(false);
//            info.setErrorMsg("您的账户余额不足,请充值!");
//            String json = writeValueAsString(info);
//            response.setContentType("application/json;charset=utf-8");
//            response.getWriter().write(json);
//            return;
//        }

        //2.3余额可以进行预定,进行转账
        int target = IOrderService.findByhid(Integer.parseInt(hid));
        IOrderService.transfer(Integer.parseInt(uid),target,paymoney);

        //2.4转账成功,生成订单,封装对象
        Order order = new Order();
        try {
            BeanUtils.populate(order,map);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        //生成订单号
        order.setOrderId(UuidUtil.getUuid());

        //下单时间
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String dateTime = LocalDateTime.now().format(formatter);
        order.setOrdertime(dateTime);

        //3.调用订单方法
        IOrderService.addOrder(order);

        //4.响应结果
        info.setFlag(true);
        writeValue(info,response);
    }
}

你可能感兴趣的:(Java毕业设计项目实战篇,java,spring,boot,mysql,FreeMarker)