基于javaweb+mysql的ssm电影售票管理系统(java+ssm+jsp+jquery+ajax+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SSM电影售票管理系统(java+ssm+jsp+jquery+ajax+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版本; 6.是否Maven项目:否;
技术栈
- 后端:Spring+SpringMVC+Mybatis 2. 前端:JSP+jQuery+Ajax
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中springmvc-servlet.xml配置文件中的数据库配置改为自己的配置; 4. 运行项目, 前台运行地址:输入localhost:8080/ssm_zxdydp/index/index.action 登录 用户账号/密码: ls/lisi 后台运行地址:localhost:8080/ssm_zxdydp/admin/index.jsp 管理员账号/密码:admin/admin
// 订单明细
@RequestMapping("orderdetail.action")
public String orderdetail(String id) {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
Details details = new Details();
details.setOrdercode(id);
List<Details> detailsList = this.detailsService.getDetailsByCond(details);
this.getRequest().setAttribute("detailsList", detailsList);
return "users/orderdetail";
}
// 按分类查询
@RequestMapping("cate.action")
public String cate(String id, String number) {
this.front();
Film goods = new Film();
goods.setCateid(id);
List<Film> flimList = new ArrayList<Film>();
List<Film> tempList = this.filmService.getFilmByCond(goods);
int pageNumber = tempList.size();
int maxPage = pageNumber;
if (maxPage % 12 == 0) {
maxPage = maxPage / 12;
} else {
maxPage = maxPage / 12 + 1;
}
if (number == null) {
number = "0";
}
int start = Integer.parseInt(number) * 12;
int over = (Integer.parseInt(number) + 1) * 12;
int count = pageNumber - over;
if (count <= 0) {
over = pageNumber;
}
for (int i = start; i < over; i++) {
Film x = tempList.get(i);
flimList.add(x);
}
String html = "";
StringBuffer buffer = new StringBuffer();
buffer.append(" 共为");
buffer.append(maxPage);
buffer.append("页 共有");
buffer.append(pageNumber);
buffer.append("条 当前为第");
buffer.append((Integer.parseInt(number) + 1));
buffer.append("页 ");
if ((Integer.parseInt(number) + 1) == 1) {
} else {
buffer.append("<a href=\"index/recommend.action?number=" + (Integer.parseInt(number) + 1) + "\">下一页</a>");
}
buffer.append(" ");
if (maxPage <= (Integer.parseInt(number) + 1)) {
buffer.append("尾页");
} else {
buffer.append("<a href=\"index/recommend.action?number=" + (maxPage - 1) + "\">尾页</a>");
}
html = buffer.toString();
this.getRequest().setAttribute("html", html);
this.getRequest().setAttribute("flimList", flimList);
return "users/list";
}
// 全部产品
@RequestMapping("all.action")
public String all(String number) {
this.front();
List<Film> flimList = new ArrayList<Film>();
List<Film> tempList = this.filmService.getAllFilm();
int pageNumber = tempList.size();
int maxPage = pageNumber;
if (maxPage % 12 == 0) {
maxPage = maxPage / 12;
} else {
maxPage = maxPage / 12 + 1;
}
if (number == null) {
number = "0";
}
int start = Integer.parseInt(number) * 12;
int over = (Integer.parseInt(number) + 1) * 12;
int count = pageNumber - over;
if (count <= 0) {
over = pageNumber;
}
for (int i = start; i < over; i++) {
Film x = tempList.get(i);
flimList.add(x);
@Resource
private UsersService usersService;
@Autowired
@Resource
private ArticleService articleService;
@Autowired
@Resource
private CateService cateService;
@Autowired
@Resource
private CityService cityService;
@Autowired
@Resource
private CinemaService cinemaService;
@Autowired
@Resource
private FilmService filmService;
@Autowired
@Resource
private CartService cartService;
@Autowired
@Resource
private OrdersService ordersService;
@Autowired
@Resource
private DetailsService detailsService;
@Autowired
@Resource
private TopicService topicService;
// 公共方法 提供公共查询数据
private void front() {
this.getRequest().setAttribute("title", "在线电影订票系统");
List<Cate> cateList = this.cateService.getAllCate();
this.getRequest().setAttribute("cateList", cateList);
List<Film> hotList = this.filmService.getFilmByHot();
this.getRequest().setAttribute("hotList", hotList);
}
// 首页显示
@RequestMapping("index.action")
public String index() {
this.front();
List<Cate> cateList = this.cateService.getCateFront();
List<Cate> frontList = new ArrayList<Cate>();
for (Cate cate : cateList) {
List<Film> flimList = this.filmService.getFilmByCate(cate.getCateid());
cate.setFlimList(flimList);
frontList.add(cate);
}
this.getRequest().setAttribute("frontList", frontList);
return "users/index";
}
int start = Integer.parseInt(number) * 12;
int over = (Integer.parseInt(number) + 1) * 12;
int count = pageNumber - over;
if (count <= 0) {
over = pageNumber;
}
for (int i = start; i < over; i++) {
Orders o = tempList.get(i);
ordersList.add(o);
}
String html = "";
StringBuffer buffer = new StringBuffer();
buffer.append(" 共为");
buffer.append(maxPage);
buffer.append("页 共有");
buffer.append(pageNumber);
buffer.append("条 当前为第");
buffer.append((Integer.parseInt(number) + 1));
buffer.append("页 ");
if ((Integer.parseInt(number) + 1) == 1) {
buffer.append("首页");
} else {
buffer.append("<a href=\"index/showOrders.action?number=0\">首页</a>");
}
buffer.append(" ");
if ((Integer.parseInt(number) + 1) == 1) {
buffer.append("上一页");
} else {
buffer.append("<a href=\"index/showOrders.action?number=" + (Integer.parseInt(number) - 1) + "\">上一页</a>");
}
buffer.append(" ");
if (maxPage <= (Integer.parseInt(number) + 1)) {
buffer.append("下一页");
} else {
buffer.append("<a href=\"index/showOrders.action?number=" + (Integer.parseInt(number) + 1) + "\">下一页</a>");
}
buffer.append(" ");
if (maxPage <= (Integer.parseInt(number) + 1)) {
buffer.append("尾页");
} else {
buffer.append("<a href=\"index/showOrders.action?number=" + (maxPage - 1) + "\">尾页</a>");
}
html = buffer.toString();
this.getRequest().setAttribute("html", html);
this.getRequest().setAttribute("ordersList", ordersList);
return "users/orderlist";
}
// 准备付款
@RequestMapping("prePay.action")
public String prePay(String id) {
// 批量删除数据
@RequestMapping("deleteCityByIds.action")
public String deleteCityByIds() {
String[] ids = this.getRequest().getParameterValues("cityid");
for (String cityid : ids) {
this.cityService.deleteCity(cityid);
}
return "redirect:/city/getAllCity.action";
}
// 更新数据
@RequestMapping("updateCity.action")
public String updateCity(City city) {
this.cityService.updateCity(city);
return "redirect:/city/getAllCity.action";
}
// 显示全部数据
@RequestMapping("getAllCity.action")
public String getAllCity(String number) {
List<City> cityList = this.cityService.getAllCity();
PageHelper.getPage(cityList, "city", null, null, 10, number, this.getRequest(), null);
return "admin/listcity";
}
// 按条件查询数据 (模糊查询)
@RequestMapping("queryCityByCond.action")
public String queryCityByCond(String cond, String name, String number) {
City city = new City();
if (cond != null) {
if ("cityname".equals(cond)) {
city.setCityname(name);
}
}
List<String> nameList = new ArrayList<String>();
List<String> valueList = new ArrayList<String>();
nameList.add(cond);
valueList.add(name);
PageHelper.getPage(this.cityService.getCityByLike(city), "city", nameList, valueList, 10, number, this.getRequest(), "query");
name = null;
cond = null;
return "admin/querycity";
}
// 按主键查询数据
@RequestMapping("getCityById.action")
public String getCityById(String id) {
City city = this.cityService.getCityById(id);
this.getRequest().setAttribute("city", city);
return "admin/editcity";
} else {
maxPage = maxPage / 12 + 1;
}
if (number == null) {
number = "0";
}
int start = Integer.parseInt(number) * 12;
int over = (Integer.parseInt(number) + 1) * 12;
int count = pageNumber - over;
if (count <= 0) {
over = pageNumber;
}
for (int i = start; i < over; i++) {
Article x = tempList.get(i);
articleList.add(x);
}
String html = "";
StringBuffer buffer = new StringBuffer();
buffer.append(" 共为");
buffer.append(maxPage);
buffer.append("页 共有");
buffer.append(pageNumber);
buffer.append("条 当前为第");
buffer.append((Integer.parseInt(number) + 1));
buffer.append("页 ");
if ((Integer.parseInt(number) + 1) == 1) {
buffer.append("首页");
} else {
buffer.append("<a href=\"index/article.action?number=0\">首页</a>");
}
buffer.append(" ");
if ((Integer.parseInt(number) + 1) == 1) {
buffer.append("上一页");
} else {
buffer.append("<a href=\"index/article.action?number=" + (Integer.parseInt(number) - 1) + "\">上一页</a>");
}
buffer.append(" ");
if (maxPage <= (Integer.parseInt(number) + 1)) {
buffer.append("下一页");
} else {
buffer.append("<a href=\"index/article.action?number=" + (Integer.parseInt(number) + 1) + "\">下一页</a>");
}
@Resource
private CinemaService cinemaService;
@Autowired
@Resource
private FilmService filmService;
@Autowired
@Resource
private CartService cartService;
@Autowired
@Resource
private OrdersService ordersService;
@Autowired
@Resource
private DetailsService detailsService;
@Autowired
@Resource
private TopicService topicService;
// 公共方法 提供公共查询数据
private void front() {
this.getRequest().setAttribute("title", "在线电影订票系统");
List<Cate> cateList = this.cateService.getAllCate();
this.getRequest().setAttribute("cateList", cateList);
List<Film> hotList = this.filmService.getFilmByHot();
this.getRequest().setAttribute("hotList", hotList);
}
// 首页显示
@RequestMapping("index.action")
public String index() {
this.front();
List<Cate> cateList = this.cateService.getCateFront();
List<Cate> frontList = new ArrayList<Cate>();
for (Cate cate : cateList) {
List<Film> flimList = this.filmService.getFilmByCate(cate.getCateid());
cate.setFlimList(flimList);
frontList.add(cate);
}
this.getRequest().setAttribute("frontList", frontList);
return "users/index";
}
// 公告
@RequestMapping("article.action")
public String article(String number) {
this.front();
List<Article> articleList = new ArrayList<Article>();
List<Article> tempList = this.articleService.getAllArticle();
cond = null;
return "admin/queryadmin";
}
// 按主键查询数据
@RequestMapping("getAdminById.action")
public String getAdminById(String id) {
Admin admin = this.adminService.getAdminById(id);
this.getRequest().setAttribute("admin", admin);
return "admin/editadmin";
}
public AdminService getAdminService() {
return adminService;
}
public void setAdminService(AdminService adminService) {
this.adminService = adminService;
}
}
//定义为控制器
@Controller
// 设置路径
@RequestMapping(value = "/details", produces = "text/plain;charset=utf-8")
public String deletecart(String id) {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
this.cartService.deleteCart(id);
return "redirect:/index/cart.action";
}
// 准备结算
@RequestMapping("preCheckout.action")
public String preCheckout() {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
String userid = (String) this.getSession().getAttribute("userid");
Cart cart = new Cart();
cart.setUsersid(userid);
List<Cart> cartList = this.cartService.getCartByCond(cart);
if (cartList.size() == 0) {
this.getSession().setAttribute("message", "请选购商品");
return "redirect:/index/cart.action";
}
List<City> cityList = this.cityService.getAllCity();
this.getRequest().setAttribute("cityList", cityList);
return "users/checkout";
}
// 结算
@RequestMapping("checkout.action")
public String checkout() {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
String userid = (String) this.getSession().getAttribute("userid");
Cart cart1 = new Cart();
cart1.setUsersid(userid);
List<Cart> cartList = this.cartService.getCartByCond(cart1);
if (cartList.size() == 0) {
this.getRequest().setAttribute("message", "请选购商品");
return "redirect:/index/cart.action";
} else {
// 获取一个1200-9999的随机数 防止同时提交
String ordercode = "PD" + VeDate.getStringDatex();
double total = 0;
for (Cart cart : cartList) {
Details details = new Details();
details.setDetailsid(VeDate.getStringDatex() + (Math.random() * 9 + 1) * 1200);
details.setFilmid(cart.getFilmid());
details.setNum(cart.getNum());
}
/**
* Action 基类
*/
@Controller
public class BaseAction {
/* 日志 */
protected final Log log = LogFactory.getLog(getClass());
/* 获取基本环境 */
public Map<String, String[]> getParameters() {// 封装为Map的requestParameters
ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
return attrs.getRequest().getParameterMap();
}
public HttpServletRequest getRequest() {
ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
return attrs.getRequest();
}
public HttpSession getSession() {
HttpSession session = null;
try {
session = this.getRequest().getSession();
} catch (Exception e) {
}
return session;
}
/* 向客户端输出操作成功或失败信息 */
public void writeJsonResponse(String success) throws IOException, JSONException {
ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
public String deleteOrdersByIds() {
String[] ids = this.getRequest().getParameterValues("ordersid");
for (String ordersid : ids) {
this.ordersService.deleteOrders(ordersid);
}
return "redirect:/orders/getAllOrders.action";
}
// 更新数据
@RequestMapping("updateOrders.action")
public String updateOrders(Orders orders) {
this.ordersService.updateOrders(orders);
return "redirect:/orders/getAllOrders.action";
}
// 显示全部数据
@RequestMapping("getAllOrders.action")
public String getAllOrders(String number) {
List<Orders> ordersList = this.ordersService.getAllOrders();
PageHelper.getPage(ordersList, "orders", null, null, 10, number, this.getRequest(), null);
return "admin/listorders";
}
// 按条件查询数据 (模糊查询)
@RequestMapping("queryOrdersByCond.action")
public String queryOrdersByCond(String cond, String name, String number) {
Orders orders = new Orders();
if(cond != null){
if ("ordercode".equals(cond)) {
orders.setOrdercode(name);
}
if ("usersid".equals(cond)) {
orders.setUsersid(name);
}
if ("total".equals(cond)) {
orders.setTotal(name);
}
if ("status".equals(cond)) {
orders.setStatus(name);
}
if ("addtime".equals(cond)) {
orders.setAddtime(name);
}
}
List<String> nameList = new ArrayList<String>();
List<String> valueList = new ArrayList<String>();
nameList.add(cond);
valueList.add(name);
PageHelper.getPage(this.ordersService.getOrdersByLike(orders), "orders", nameList, valueList, 10, number, this.getRequest(), "query");
public String updateFilm(Film film) {
this.filmService.updateFilm(film);
return "redirect:/film/getAllFilm.action";
}
// 显示全部数据
@RequestMapping("getAllFilm.action")
public String getAllFilm(String number) {
List<Film> filmList = this.filmService.getAllFilm();
PageHelper.getPage(filmList, "film", null, null, 10, number, this.getRequest(), null);
return "admin/listfilm";
}
// 按条件查询数据 (模糊查询)
@RequestMapping("queryFilmByCond.action")
public String queryFilmByCond(String cond, String name, String number) {
Film film = new Film();
if (cond != null) {
if ("filmname".equals(cond)) {
film.setFilmname(name);
}
if ("image".equals(cond)) {
film.setImage(name);
}
if ("cateid".equals(cond)) {
film.setCateid(name);
}
if ("price".equals(cond)) {
film.setPrice(name);
}
if ("recommend".equals(cond)) {
film.setRecommend(name);
}
if ("thestart".equals(cond)) {
film.setThestart(name);
}
if ("theend".equals(cond)) {
film.setTheend(name);
}
if ("hits".equals(cond)) {
film.setHits(name);
}
orders.setUsersid(userid);
this.ordersService.insertOrders(orders);
}
return "redirect:/index/showOrders.action";
}
// 查看订购
@RequestMapping("showOrders.action")
public String showOrders(String number) {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
String userid = (String) this.getSession().getAttribute("userid");
Orders orders = new Orders();
orders.setUsersid(userid);
List<Orders> ordersList = new ArrayList<Orders>();
List<Orders> tempList = this.ordersService.getOrdersByCond(orders);
int pageNumber = tempList.size();
int maxPage = pageNumber;
if (maxPage % 12 == 0) {
maxPage = maxPage / 12;
} else {
maxPage = maxPage / 12 + 1;
}
if (number == null) {
number = "0";
}
int start = Integer.parseInt(number) * 12;
int over = (Integer.parseInt(number) + 1) * 12;
int count = pageNumber - over;
if (count <= 0) {
over = pageNumber;
}
for (int i = start; i < over; i++) {
Orders o = tempList.get(i);
ordersList.add(o);
}
String html = "";
StringBuffer buffer = new StringBuffer();
buffer.append(" 共为");
buffer.append(maxPage);
buffer.append("页 共有");
buffer.append(pageNumber);
buffer.append("条 当前为第");
buffer.append((Integer.parseInt(number) + 1));
} else {
buffer.append("<a href=\"" + name + "/" + action + "?number=" + (Integer.parseInt(number) + 1) + "" + path + "\">下一页</a>");
}
buffer.append(" ");
if (maxPage <= (Integer.parseInt(number) + 1)) {
buffer.append("尾页");
} else {
buffer.append("<a href=\"" + name + "/" + action + "?number=" + (maxPage - 1) + "" + path + "\">尾页</a>");
}
String html = buffer.toString();
request.setAttribute("html", html);
request.setAttribute(name + "List", objList);
}
}
@Controller
@RequestMapping("/upload")
public class UploadAction {
@RequestMapping(value = "/image.action")
public String upload(@RequestParam(value = "image", required = false) MultipartFile file,
HttpServletRequest request, ModelMap model) {
String path = request.getSession().getServletContext().getRealPath("/") + "upfiles/";
String fileName = file.getOriginalFilename();
int i = fileName.lastIndexOf(".");
String name = String.valueOf(VeDate.getStringDatex());
String type = fileName.substring(i + 1);
fileName = name + "." + type;
File targetFile = new File(path, fileName);
if (!targetFile.exists()) {
targetFile.mkdirs();
}
// 保存
try {
file.transferTo(targetFile);
} catch (Exception e) {
e.printStackTrace();
}
}
}
//定义为控制器
@Controller
// 设置路径
@RequestMapping(value = "/orders" , produces = "text/plain;charset=utf-8")
public class OrdersAction extends BaseAction {
// 注入Service 由于标签的存在 所以不需要getter setter
@Autowired
@Resource
private OrdersService ordersService;
@Autowired
@Resource
private UsersService usersService;
// 准备添加数据
@RequestMapping("createOrders.action")
public String createOrders() {
List<Users> usersList = this.usersService.getAllUsers();
this.getRequest().setAttribute("usersList", usersList);
return "admin/addorders";
}
// 添加数据
@RequestMapping("addOrders.action")
public String addOrders(Orders orders) {
this.ordersService.insertOrders(orders);
return "redirect:/orders/createOrders.action";
}
// 通过主键删除数据
@RequestMapping("deleteOrders.action")
public String deleteOrders(String id) {
this.front();
return "users/login";
}
// 用户登录
@RequestMapping("login.action")
public String login() {
this.front();
String username = this.getRequest().getParameter("username");
String password = this.getRequest().getParameter("password");
Users u = new Users();
u.setUsername(username);
List<Users> usersList = this.usersService.getUsersByCond(u);
if (usersList.size() == 0) {
this.getSession().setAttribute("message", "用户名不存在");
return "redirect:/index/preLogin.action";
} else {
Users users = usersList.get(0);
if (password.equals(users.getPassword())) {
this.getSession().setAttribute("userid", users.getUsersid());
this.getSession().setAttribute("username", users.getUsername());
this.getSession().setAttribute("users", users);
return "redirect:/index/index.action";
} else {
this.getSession().setAttribute("message", "密码错误");
return "redirect:/index/preLogin.action";
}
}
}
// 准备注册
@RequestMapping("preReg.action")
public String preReg() {
this.front();
return "users/register";
}
// 用户注册
@RequestMapping("register.action")
public String register(Users users) {
this.front();
Users u = new Users();
u.setUsername(users.getUsername());
List<Users> usersList = this.usersService.getUsersByCond(u);
if (usersList.size() == 0) {
users.setRegdate(VeDate.getStringDateShort());
this.usersService.insertUsers(users);
} else {
this.getSession().setAttribute("message", "用户名已存在");
return "redirect:/index/preReg.action";
}
return "redirect:/index/preLogin.action";
// 准备结算
@RequestMapping("preCheckout.action")
public String preCheckout() {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
String userid = (String) this.getSession().getAttribute("userid");
Cart cart = new Cart();
cart.setUsersid(userid);
List<Cart> cartList = this.cartService.getCartByCond(cart);
if (cartList.size() == 0) {
this.getSession().setAttribute("message", "请选购商品");
return "redirect:/index/cart.action";
}
List<City> cityList = this.cityService.getAllCity();
this.getRequest().setAttribute("cityList", cityList);
return "users/checkout";
}
// 结算
@RequestMapping("checkout.action")
public String checkout() {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
String userid = (String) this.getSession().getAttribute("userid");
Cart cart1 = new Cart();
cart1.setUsersid(userid);
List<Cart> cartList = this.cartService.getCartByCond(cart1);
if (cartList.size() == 0) {
this.getRequest().setAttribute("message", "请选购商品");
return "redirect:/index/cart.action";
} else {
// 获取一个1200-9999的随机数 防止同时提交
String ordercode = "PD" + VeDate.getStringDatex();
double total = 0;
for (Cart cart : cartList) {
Details details = new Details();
details.setDetailsid(VeDate.getStringDatex() + (Math.random() * 9 + 1) * 1200);
details.setFilmid(cart.getFilmid());
details.setNum(cart.getNum());
details.setOrdercode(ordercode);
details.setPrice(cart.getPrice());