基于javaweb+mysql的ssm航班机票预订平台系统(java+ssm+js+jsp+mysql)
私信源码获取及调试交流
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb的SSM航班机票预订平台系统(java+ssm+js+jsp+mysql)
项目介绍
管理员角色包含以下功能: 管理员登录,用户管理,客机管理,航班管理,机票管理,密码修改等功能。
用户角色包含以下功能: 查看所有机票,用户登录注册,机票预订,查看我的订单等功能。
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 5.数据库:MySql 5.7版本;
技术栈
- 后端:Spring+SpringMVC+Mybatis 2. 前端:HTML+CSS+JavaScript+jsp
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中application.yml配置文件中的数据库配置改为自己的配置; 4. 运行项目,输入localhost:8080/ 登录
System.out.println("user----save-----");
JSONObject result = new JSONObject();
String id = request.getParameter("id");
boolean flag = false;
Integer i;
if (id == null) {//添加操作
i = userService.insertSelective(user);
} else {//修改操作
i = userService.updateByPrimaryKeySelective(user);
}
if (i > 0) {
flag = true;
}
result.put("success", flag);
ResponseUtil.write(response, result);
return null;
}
@RequestMapping("/userCenter")
public String userCenter() {
return "main_userCenter";
}
@RequestMapping("/logout")
public String logout(HttpServletRequest request, HttpServletResponse response) throws Exception {
JSONObject result = new JSONObject();
HttpSession session = request.getSession();
session.removeAttribute("currentUser");
session.invalidate();
cookiesUtil.deleteCookies(cookieName,request, response);
result.put("success", true);
ResponseUtil.write(response, result);
return "main";
}
@RequestMapping("/adminManagerPage")
public String managerList() {
return "admin/userManage";
}
cookiesUtil.deleteCookies(cookieName,request, response);
result.put("success", true);
ResponseUtil.write(response, result);
return "main";
}
@RequestMapping("/adminManagerPage")
public String managerList() {
return "admin/userManage";
}
@RequestMapping("/search")
public String search() {
return "login";
}
public Integer getCurrentUserId() {
return currentUserId;
}
public void setCurrentUserId(Integer currentUserId) {
this.currentUserId = currentUserId;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@RequestMapping("/adminDeleteTicketOrder")
public String adminDeleteTicketOrder(HttpServletResponse response, HttpServletRequest request) {
String ids = request.getParameter("ids");
String[] split = ids.split(",");
JSONObject result = new JSONObject();
boolean flag = false;
int count = 0;
try {
for (String i : split) {
Integer integer = ticketOrderService.deleteByPrimaryKey(Integer.parseInt(i));
count++;
}
if (count == split.length) {
flag = true;
}
result.put("success", flag);
ResponseUtil.write(response, result);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@RequestMapping("/adminFlightList")
public String adminFlightList(HttpServletRequest request, Flight flight, HttpServletResponse response) {
PageBean pageBean = new PageBean();
JSONObject result = new JSONObject();
String page = request.getParameter("page");
String rows = request.getParameter("rows");
//String s_fromTime = request.getParameter("s_fromTime");
// list_flight = new Flight();
if (rows != null) {
pageBean.setPageSize(Integer.parseInt(rows));
flight.setPageSize(pageBean.getPageSize());
}
if (page != null) {
pageBean.setPage(Integer.parseInt(page));
flight.setPage(pageBean.getStart());
}
if (flight.getFromTime() != null) {
flight.setFromtime(DateUtil.formatString(flight.getFromTime() + " 00:00:00", format));
}
try {
Integer count = flightService.getCount(flight);
List<Flight> flightList = flightService.getIndexList(flight);
@RequestMapping("/indexList")
public ModelAndView indexList() {
ModelAndView mav = new ModelAndView();
PageBean pageBean = new PageBean(1, 5);
index_flight = getFlight(pageBean);
index_flight.setFlighttype(flightType1);
flightList1 = flightService.getIndexList(index_flight);
index_flight.setFlighttype(flightType2);
flightList2 = flightService.getIndexList(index_flight);
mav.addObject("flightList1", flightList1);
mav.addObject("flightList2", flightList2);
mav.setViewName(viewName);
return mav;
}
@RequestMapping("/search")
public ModelAndView search(Flight flight, HttpServletRequest request) throws ParseException {
String page = request.getParameter("page");
String departTime = request.getParameter("departTime");
Date dateFrom = null;
Date dateTo = null;
if(departTime!=null&&!departTime.equals("")){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
dateFrom = sdf.parse(departTime+" 00:00:00");
dateTo = sdf.parse(departTime+" 23:59:59");
}
if (page == null) {
page = "1";
}
PageBean pageBean = new PageBean(Integer.parseInt(page), 10);
flight.setPage(pageBean.getStart());
flight.setPageSize(pageBean.getPageSize());
flight.setDateFrom(dateFrom);
flight.setDateTo(dateTo);
Integer count = flightService.getCount(flight);
flightList = flightService.getIndexList(flight);
// getPageNum(count, pageBean);
ModelAndView mav = getPageCode(count, pageBean, request);
return mav;
}
@RequestMapping("/list")
public ModelAndView list(HttpServletRequest request) {
PageBean pageBean = null;
Flight flight = new Flight();
String page = request.getParameter("page");
if (page != null) {
pageBean = new PageBean(Integer.parseInt(page), 10);
}
flight.setPage(pageBean.getStart());
flight.setPageSize(pageBean.getPageSize());
public void setCurrentUserId(Integer currentUserId) {
this.currentUserId = currentUserId;
}
}
/**
* com.chen.ssm.web
* 作者 : 陈晓
* 描述 :
* 修改日期 :
*/
@Controller
@RequestMapping("/aircraft")
public class AircraftController /*extends BaseController*/ {
@Resource
private AircraftService aircraftService;
Manager managerUser = managerService.ManagerLogin(manager);
if (managerUser != null) {
session.setAttribute("adminUser", managerUser.getUsername());
session.setAttribute("currentUser", managerUser);
cookiesUtil.addcookie(cookieName, managerUser.getUsername(), 1800, response);
} else {
if(manager != null&&null != manager.getUsername()) {
session.setAttribute("message", "用户名或密码有误!!!");
}else {
session.setAttribute("message", "");
}
return loginPage;
}
return "admin/main";
}
@RequestMapping("/adminIndex")
public String adminIndex() {
return "admin/main";
}
@RequestMapping("/logout")
public String logout(HttpServletResponse response, HttpServletRequest request) {
JSONObject result = new JSONObject();
HttpSession session = request.getSession();
session.invalidate();
cookiesUtil.deleteCookies(cookieName,request,response);
result.put("success", true);
ResponseUtil.write(response, result);
return null;
}
@RequestMapping("/modifyPassword")
public String modifyPassword(Manager manager, HttpServletRequest request, HttpServletResponse response) {
JSONObject result = new JSONObject();
boolean flag = false;
int i = managerService.modifyPassword(manager.getId());
if (i > 0) {
@RequestMapping("/myTicketOrderList")
public ModelAndView myTicketOrderList(HttpServletRequest request) {
ModelAndView mav = new ModelAndView();
String currentUser = request.getSession().getAttribute("currentUser").toString();
List<Ticketorder> ticketOrderList = ticketOrderService.getTicketOrderByUserName(currentUser);
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.registerJsonValueProcessor(Date.class, jsonDateValueProcessor);
JSONArray array = JSONArray.fromObject(ticketOrderList, jsonConfig);
mav.addObject("ticketOrderList",array);
mav.setViewName("main_userCenter");
request.setAttribute("mainPage","ticket/myTicketOrderList.jsp");
return mav;
}
@RequestMapping("/preTicketOrder")
public ModelAndView preTicketOrder(HttpServletRequest request){
Integer flightId = Integer.parseInt(request.getParameter("flightId"));
String currentUser = request.getSession().getAttribute("currentUser").toString();
User user = userService.getUserByUsername(currentUser);
Flight flight = flightService.selectByPrimaryKey(flightId);
ModelAndView mav = new ModelAndView();
mav.addObject("flight",flight);
mav.addObject("currentUser",user);
mav.setViewName("main_userCenter");
request.setAttribute("mainPage","ticket/ticketOrder.jsp");
return mav;
}
@RequestMapping("/saveTicketOrder")
public ModelAndView saveTicketOrder(HttpServletRequest request){
ModelAndView mav = new ModelAndView();
Integer flightId = Integer.parseInt(request.getParameter("flightid"));
Integer pricetype = Integer.parseInt(request.getParameter("pricetype"));
Integer num = Integer.parseInt(request.getParameter("num"));
String currentUser = request.getSession().getAttribute("currentUser").toString();
User user = userService.getUserByUsername(currentUser);
Flight flight = flightService.selectByPrimaryKey(flightId);
int ticketRemain = 0;
int singlePrice = 0;
if(pricetype==1){//经济舱
ticketRemain = flight.getEcticketremain();
}
}
/**
* com.chen.ssm.web
* 作者 : 陈晓
* 描述 :
* 修改日期 :
*/
@Controller
@RequestMapping("/ticket")
public class TicketOrderController {
@Resource
private TicketOrderService ticketOrderService;
@Resource
private FlightService flightService;
@Resource
private UserService userService;
private String format = "yyyy-MM-dd HH:mm:ss";
private JsonDateValueProcessor jsonDateValueProcessor = new JsonDateValueProcessor(format);
/**
* com.chen.ssm.web
* 作者 : 陈晓
* 描述 :
* 修改日期 :
*/
@Controller
@RequestMapping("/flight")
public class FlightController {
private HttpServletRequest request;
private HttpServletResponse response;
private List<Flight> flightList;
private List<Ticketorder> ticketorderList;
private List<Flight> flightList1; // 国内航班
private List<Flight> flightList2; // 国际航班
private Flight search_flight;
private Flight list_flight;
private Flight index_flight;
private String flightType1 = "国内航班";
private String flightType2 = "国际航班";
private String viewName = "main";
private String page = null;
private Integer pageCount;
private String pageLi2 = "页</a></li>";
private String pageCode;
//private PageBean pageBean;
private PageUtil pageUtil = new PageUtil();
private String format = "yyyy-MM-dd HH:mm:ss";
private boolean flag = false;
@Resource
/**
* com.chen.ssm.web
* 作者 : 陈晓
* 描述 :
* 修改日期 :
*/
@Controller
@RequestMapping("/aircraft")
public class AircraftController /*extends BaseController*/ {
@Resource
private AircraftService aircraftService;
@Resource
private FlightService flightService;
private List<Flight> flightList;
// 定义转换日期类型的输出格式
private String format = "yyyy-MM-dd";
private boolean flag = false;
// private Aircraft aircraft;
@RequestMapping("/adminAircraftPage")
public String aircraftList() {
return "admin/aircraftManage";
}
@InitBinder
public void initBinder(WebDataBinder binder) {
binder.registerCustomEditor(Date.class, new DateUtil());
}
@RequestMapping("/save")
@ResponseBody
public Object save(Aircraft aircraft, HttpServletResponse response, HttpServletRequest request) {
JSONObject result = new JSONObject();
// String id = request.getParameter("id");
String buyDate = request.getParameter("buyDate");
String useDate = request.getParameter("useDate");
//String name = request.getParameter("name");
// String remark = request.getParameter("remark");
DateUtil dateUtil = new DateUtil();
String flightId = "";
String message = "";
int count = 0;
try {
for (String i : split) {
flightList = flightService.selectListByAircraftId(Integer.parseInt(i));
if (flightList.size() > 0) {
flightId = flightId + i + ",";
continue;
} else {
Integer integer = aircraftService.deleteByPrimaryKey(Integer.parseInt(i));
count++;
}
}
if (count == split.length) {
flag = true;
message = "数据全部成功删除!";
} else {
message = "id为" + flightId.substring(0, flightId.length() - 1) + "的客机有航班任务,不可进行删除操作!";
}
result.put("success", flag);
result.put("message", message);
ResponseUtil.write(response, result);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@RequestMapping("/adminAircraftList")
public String adminAircraftList(HttpServletRequest request, Aircraft aircraft, HttpServletResponse response) {
PageBean pageBean = new PageBean();
JSONObject result = new JSONObject();
String page = request.getParameter("page");
String rows = request.getParameter("rows");
if (rows != null) {
pageBean.setPageSize(Integer.parseInt(rows));
aircraft.setPageSize(pageBean.getPageSize());
}
if (page != null) {
pageBean.setPage(Integer.parseInt(page));
aircraft.setPage(pageBean.getStart());
}
try {
boolean flag = false;
String flightId = "";
String message = "";
int count = 0;
try {
for (String i : split) {
flightList = flightService.selectListByAircraftId(Integer.parseInt(i));
if (flightList.size() > 0) {
flightId = flightId + i + ",";
continue;
} else {
Integer integer = aircraftService.deleteByPrimaryKey(Integer.parseInt(i));
count++;
}
}
if (count == split.length) {
flag = true;
message = "数据全部成功删除!";
} else {
message = "id为" + flightId.substring(0, flightId.length() - 1) + "的客机有航班任务,不可进行删除操作!";
}
result.put("success", flag);
result.put("message", message);
ResponseUtil.write(response, result);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@RequestMapping("/adminAircraftList")
public String adminAircraftList(HttpServletRequest request, Aircraft aircraft, HttpServletResponse response) {
PageBean pageBean = new PageBean();
JSONObject result = new JSONObject();
String page = request.getParameter("page");
String rows = request.getParameter("rows");
if (rows != null) {
pageBean.setPageSize(Integer.parseInt(rows));
aircraft.setPageSize(pageBean.getPageSize());
}
if (i > 0) {
flag = true;
}
result.put("success", flag);
ResponseUtil.write(response, result);
return null;
}
@RequestMapping("/adminUserList")
public String adminUserList(User user, HttpServletResponse response, HttpServletRequest request) throws Exception {
PageBean pageBean = new PageBean();
String page = request.getParameter("page");
String rows = request.getParameter("rows");
if (rows != null) {
pageBean.setPageSize(Integer.parseInt(rows));
user.setPageSize(pageBean.getPageSize());
}
if (page != null) {
pageBean.setPage(Integer.parseInt(page));
user.setPage(pageBean.getStart());
}
List<User> userList = userService.getUserList(user);
Integer total = userService.getCount(user);
JsonConfig jsonConfig = new JsonConfig();
JSONArray array = JSONArray.fromObject(userList, jsonConfig);
JSONObject result = new JSONObject();
result.put("total", total);
result.put("rows", array);
ResponseUtil.write(response, result);
return null;
}
@RequestMapping("/deleteUser")
public String deleteUser(HttpServletResponse response, HttpServletRequest request) {
String ids = request.getParameter("ids");
String[] split = ids.split(",");
JSONObject result = new JSONObject();
String message = "用户有订单,不能进行删除操作!";
String userID = "";
boolean flag = false;
int count = 0;
try {
for (String i : split) {
ticketorderList = ticketOrderService.selectListByUserId(Integer.parseInt(i));
if (ticketorderList.size() > 0) {
userID = userID + i + ",";
continue;
} else {
Integer integer = userService.deleteByPrimaryKey(Integer.parseInt(i));
count++;
}
}
if (count == split.length) {
ResponseUtil.write(response, result);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@RequestMapping("/managerLoginPage")
public String managerLoginPage() {
return loginPage;
}
}
/**
* com.chen.ssm.web
* 作者 : 陈晓
* 描述 :
* 修改日期 :
*/
@Controller
@RequestMapping("/flight")
}
if (count == split.length) {
flag = true;
}
result.put("success", flag);
ResponseUtil.write(response, result);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@RequestMapping("/adminFlightList")
public String adminFlightList(HttpServletRequest request, Flight flight, HttpServletResponse response) {
PageBean pageBean = new PageBean();
JSONObject result = new JSONObject();
String page = request.getParameter("page");
String rows = request.getParameter("rows");
//String s_fromTime = request.getParameter("s_fromTime");
// list_flight = new Flight();
if (rows != null) {
pageBean.setPageSize(Integer.parseInt(rows));
flight.setPageSize(pageBean.getPageSize());
}
if (page != null) {
pageBean.setPage(Integer.parseInt(page));
flight.setPage(pageBean.getStart());
}
if (flight.getFromTime() != null) {
flight.setFromtime(DateUtil.formatString(flight.getFromTime() + " 00:00:00", format));
}
try {
Integer count = flightService.getCount(flight);
List<Flight> flightList = flightService.getIndexList(flight);
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor(format));
JSONArray array = JSONArray.fromObject(flightList, jsonConfig);
result.put("rows", array);
result.put("total", count);
ResponseUtil.write(response, result);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public String managerLoginPage() {
return loginPage;
}
}
/**
* com.chen.ssm.web
* 作者 : 陈晓
* 描述 :
* 修改日期 :
*/
@Controller
@RequestMapping("/flight")
public class FlightController {
//String s_fromTime = request.getParameter("s_fromTime");
// list_flight = new Flight();
if (rows != null) {
pageBean.setPageSize(Integer.parseInt(rows));
flight.setPageSize(pageBean.getPageSize());
}
if (page != null) {
pageBean.setPage(Integer.parseInt(page));
flight.setPage(pageBean.getStart());
}
if (flight.getFromTime() != null) {
flight.setFromtime(DateUtil.formatString(flight.getFromTime() + " 00:00:00", format));
}
try {
Integer count = flightService.getCount(flight);
List<Flight> flightList = flightService.getIndexList(flight);
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor(format));
JSONArray array = JSONArray.fromObject(flightList, jsonConfig);
result.put("rows", array);
result.put("total", count);
ResponseUtil.write(response, result);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@RequestMapping("/adminDeleteFlight")
public String adminDeleteFlight(HttpServletResponse response, HttpServletRequest request) {
String ids = request.getParameter("ids");
String[] split = ids.split(",");
JSONObject result = new JSONObject();
boolean flag = false;
String flightId = "";
String message = "";
int count = 0;
try {
for (String i : split) {
ticketorderList = ticketOrderService.selectListByFlightId(Integer.parseInt(i));
if (ticketorderList.size() > 0) {
flightId = flightId + i + ",";
continue;
} else {
Integer integer = flightService.deleteByPrimaryKey(Integer.parseInt(i));
count++;
}
}
if (count == split.length) {
flag = true;
message = "数据全部成功删除!";
}
PageBean pageBean = new PageBean(Integer.parseInt(page), 10);
flight.setPage(pageBean.getStart());
flight.setPageSize(pageBean.getPageSize());
flight.setDateFrom(dateFrom);
flight.setDateTo(dateTo);
Integer count = flightService.getCount(flight);
flightList = flightService.getIndexList(flight);
// getPageNum(count, pageBean);
ModelAndView mav = getPageCode(count, pageBean, request);
return mav;
}
@RequestMapping("/list")
public ModelAndView list(HttpServletRequest request) {
PageBean pageBean = null;
Flight flight = new Flight();
String page = request.getParameter("page");
if (page != null) {
pageBean = new PageBean(Integer.parseInt(page), 10);
}
flight.setPage(pageBean.getStart());
flight.setPageSize(pageBean.getPageSize());
Integer count = flightService.getCount(flight);
flightList = flightService.getIndexList(flight);
// getPageNum(count, pageBean);
ModelAndView mav = getPageCode(count, pageBean, request);
return mav;
}
@RequestMapping("/save")
@ResponseBody
public Object save(Flight flight, HttpServletResponse response, HttpServletRequest request) {
JSONObject result = new JSONObject();
String fromTime = request.getParameter("fromTime");
String toTime = request.getParameter("toTime");
DateUtil dateUtil = new DateUtil();
flight.setFromtime(dateUtil.formatString(fromTime, format));
flight.setTotime(dateUtil.formatString(toTime, format));
Integer i = 0;
System.out.println("=========" + flight.getId());
try {
if (flight.getId() == null) {//用户添加
String fcTicketTotal = request.getParameter("fctickettotal");
String ecTicketTotal = request.getParameter("ectickettotal");
flight.setEcticketremain(Integer.parseInt(ecTicketTotal));
flight.setFcticketremain(Integer.parseInt(fcTicketTotal));
i = flightService.insertSelective(flight);