• 大小: 1.63MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-10-11
  • 语言: Java
  • 标签: Java  售票  

资源简介

用Java技术仿12306简单实现售票功能,不带JSP页面,纯功能实现

资源截图

代码片段和文件信息

package com.lxn.controller;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Scanner;

import com.lxn.entity.Ticket;
import com.lxn.entity.Train;
import com.lxn.entity.User;
import com.lxn.service.OrderService;
import com.lxn.service.StationService;
import com.lxn.service.TicketService;
import com.lxn.service.TrainService;
import com.lxn.service.UserService;
import com.lxn.service.impl.OrderServiceImpl;
import com.lxn.service.impl.StationServiceImpl;
import com.lxn.service.impl.TicketServiceImpl;
import com.lxn.service.impl.TrainServiceImpl;
import com.lxn.service.impl.UserServiceImpl;
import com.lxn.view.View;

public class Controller {

UserService userService = new UserServiceImpl();// 组合
static TrainService trainService = new TrainServiceImpl();
StationService stationService = new StationServiceImpl();
static TicketService ticketService = new TicketServiceImpl();
OrderService orderService = new OrderServiceImpl();

static Calendar calendar = Calendar.getInstance();
static DateFormat df = new SimpleDateFormat(“yyyy-MM-dd HH:mm“);// 日期--->字符串
static DateFormat df3 = new SimpleDateFormat(“yyyy-MM-dd“);// 字符串--->日期

static Scanner sc = new Scanner(System.in);

static boolean loginFalg = false;
static User loginuser = null;

public void dispatcher() {

while (true) {
// 【1--注册 2--登录 3--查询4---退出】
int choice = View.homePage();

// 注册
if (choice == 1) {

System.out.println(“请输入手机号“);
String phoneNumber = sc.next();

if (userService.checkPhonenumber(phoneNumber)) {

System.out.println(“请输入密码“);
String password = sc.next();

System.out.println(“请输入用户名“);
String username = sc.next();

int accountbalance = 0;
int role = 1;

User user = new User(username phoneNumber password accountbalance role);

if (userService.register(user)) {
System.out.println(“注册成功“);
} else {
System.out.println(“注册失败,请检查手机号和密码“);
}

} else {
System.out.println(“手机号已注册,请重新输入或登录“);
}

} else if (choice == 2) { // 登录

System.out.println(“请输入手机号“);
String phoneNumber = sc.next();

System.out.println(“请输入密码“);
String password = sc.next();

loginuser = userService.login(phoneNumber password);

if (loginuser != null) {

System.out.println(“登录成功“);
loginFalg=true;

// 判断角色,调用方法
int role = loginuser.getRole();
if (role == 1) {

// 用户
UserController userController=new UserController();
userController.dispatcher();

} else if (role == 2) {

// 管理员
ManagerController managerController=new ManagerController();
managerController.dispatcher();

}

} else {
System.out.println(“登录失败,请检查手机号和密码“);
}
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-10-31 19:46  Project3\
     文件         310  2018-10-20 11:29  Project3\.classpath
     文件         384  2018-10-20 11:20  Project3\.project
     目录           0  2018-10-31 19:46  Project3\bin\
     目录           0  2018-10-31 19:46  Project3\bin\com\
     目录           0  2018-10-31 19:46  Project3\bin\com\lxn\
     目录           0  2018-10-31 19:46  Project3\bin\com\lxn\controller\
     文件        7185  2018-10-29 20:05  Project3\bin\com\lxn\controller\Controller.class
     文件        9184  2018-10-31 12:19  Project3\bin\com\lxn\controller\ManagerController.class
     文件         533  2018-10-29 09:03  Project3\bin\com\lxn\controller\Test.class
     文件       12730  2018-10-31 12:04  Project3\bin\com\lxn\controller\UserController.class
     目录           0  2018-10-31 19:46  Project3\bin\com\lxn\dao\
     文件         456  2018-10-31 10:16  Project3\bin\com\lxn\dao\OrderDAO.class
     文件         278  2018-10-29 09:03  Project3\bin\com\lxn\dao\StationDAO.class
     文件         476  2018-10-31 10:11  Project3\bin\com\lxn\dao\TicketDAO.class
     文件         716  2018-10-29 19:03  Project3\bin\com\lxn\dao\TrainDAO.class
     文件         504  2018-10-31 12:11  Project3\bin\com\lxn\dao\UserDAO.class
     目录           0  2018-10-31 19:46  Project3\bin\com\lxn\dao\impl\
     文件        3737  2018-10-31 10:16  Project3\bin\com\lxn\dao\impl\OrderDAOImpl.class
     文件        2728  2018-10-29 09:03  Project3\bin\com\lxn\dao\impl\StationDAOImpl.class
     文件        4605  2018-10-31 10:11  Project3\bin\com\lxn\dao\impl\TicketDAOImpl.class
     文件        5732  2018-10-29 19:14  Project3\bin\com\lxn\dao\impl\TrainDAOImpl.class
     文件        5340  2018-10-31 12:12  Project3\bin\com\lxn\dao\impl\UserDAOImpl.class
     目录           0  2018-10-31 19:46  Project3\bin\com\lxn\dbutil\
     文件        3926  2018-10-29 09:03  Project3\bin\com\lxn\dbutil\DBManager.class
     文件         109  2018-10-26 14:21  Project3\bin\com\lxn\dbutil\dbconfig.properties
     目录           0  2018-10-31 19:46  Project3\bin\com\lxn\entity\
     文件        2454  2018-10-29 09:03  Project3\bin\com\lxn\entity\OrderInfo.class
     文件        1703  2018-10-29 09:03  Project3\bin\com\lxn\entity\Station.class
     文件        1745  2018-10-29 09:03  Project3\bin\com\lxn\entity\Ticket.class
     文件        2475  2018-10-29 09:03  Project3\bin\com\lxn\entity\Train.class
............此处省略66个文件信息

评论

共有 条评论