项目介绍
基于Spring,SpringMVC,Mybatis开发实现。
数据库用的是MySQL5.5。
开发工具用的Eclipse + Tomcat7,JDK1.7-1.8皆可。
效果图展示
首页
电影详情页
购票
登录注册页面
后台管理页面
电影信息列表
添加电影信息
电影票管理
订单管理
热点新闻管理
实现逻辑代码
抽出一些核心代码,如有BUG和问题,欢迎指出。
MovieController
package com.app.controller; import java.util.HashMap; import java.util.List; import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; import com.app.bean.Movies; import com.app.bean.Orders; import com.app.bean.Ticket; import com.app.service.MovieService; import com.app.util.StringUtilsEx; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import static com.app.util.StringUtilsEx.*; @Controller @RequestMapping("/movie") public class MovieController { @Autowired private MovieService ms; @RequestMapping("/listOrder") @ResponseBody public MaplistOrder(Integer page,Integer rows){ Map result = new HashMap<>(); List list = null; try { if(isEmpty(page) || isEmpty(rows)) { page = 1; rows = 5; } PageHelper.startPage(page, rows); list = ms.listOrder(); result.put("rows", list); PageInfo pageInfo = new PageInfo (list); result.put("total", pageInfo.getTotal()); } catch (Exception e) { e.printStackTrace(); return null; } return result; } //根据电影票ID生成订单 @RequestMapping("/addOrder") @ResponseBody public Map addOrder(String id){ Map returnVo = new HashMap (); returnVo.put("code", 0); try{ ms.addOrder(id); }catch(Exception e){ returnVo.put("code", -1); } return returnVo; } @RequestMapping("/getById") @ResponseBody public Movies getById(String id){ return ms.getById(id); } @RequestMapping("/createTickets") @ResponseBody public Map createTickets(String id){ Map returnVo = new HashMap (); returnVo.put("code", 0); //先检查这个id的电影是否已经生成了电影票 List tickets = ms.getTicketsByMovieId(id); if(tickets != null && !tickets.isEmpty()){ returnVo.put("code", 2); return returnVo; } try{ ms.createTickets(id); }catch(Exception e){ returnVo.put("code", -1); } return returnVo; } @RequestMapping("/update") @ResponseBody public Map update(String id,String column){ Map returnVo = new HashMap (); returnVo.put("code", 0); try{ ms.update(id,column); }catch(Exception e){ returnVo.put("code", -1); } return returnVo; } @RequestMapping("/delete") @ResponseBody public Map delete(String id){ Map returnVo = new HashMap (); returnVo.put("code", 0); try{ ms.delete(id); }catch(Exception e){ returnVo.put("code", -1); } return returnVo; } @RequestMapping("/add") @ResponseBody public Map add(Movies movie){ Map returnVo = new HashMap (); returnVo.put("code", 0); try{ if(StringUtilsEx.isNotEmpty(movie.getId())){ ms.update(movie); }else{ ms.add(movie); } }catch(Exception e){ e.printStackTrace(); returnVo.put("code", -1); } return returnVo; } @RequestMapping("/list") @ResponseBody public Map list(String moviename,Integer page,Integer rows){ Map result = new HashMap<>(); List list = null; try { if(isEmpty(page) || isEmpty(rows)) { page = 1; rows = 5; } PageHelper.startPage(page, rows); list = ms.list(moviename); result.put("rows", list); PageInfo pageInfo = new PageInfo (list); result.put("total", pageInfo.getTotal()); } catch (Exception e) { e.printStackTrace(); return null; } return result; } }
NewsController
package com.app.controller; import java.util.HashMap; import java.util.List; import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; import com.app.bean.Movies; import com.app.bean.News; import com.app.service.MovieService; import com.app.service.NewsService; import com.app.util.StringUtilsEx; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import static com.app.util.StringUtilsEx.*; @Controller @RequestMapping("/news") public class NewsController { @Autowired private NewsService service; @RequestMapping("/getById") @ResponseBody public News getById(String id){ return service.getById(id); } @RequestMapping("/delete") @ResponseBody public Mapdelete(String id){ Map returnVo = new HashMap (); returnVo.put("code", 0); try{ service.delete(id); }catch(Exception e){ returnVo.put("code", -1); } return returnVo; } @RequestMapping("/add") @ResponseBody public Map add(News news){ Map returnVo = new HashMap (); returnVo.put("code", 0); try{ if(StringUtilsEx.isNotEmpty(news.getId())){ service.update(news); }else{ service.add(news); } }catch(Exception e){ e.printStackTrace(); returnVo.put("code", -1); } return returnVo; } @RequestMapping("/list") @ResponseBody public Map list(String newsname,Integer page,Integer rows){ Map result = new HashMap<>(); List list = null; try { if(isEmpty(page) || isEmpty(rows)) { page = 1; rows = 5; } PageHelper.startPage(page, rows); list = service.list(newsname); result.put("rows", list); PageInfo pageInfo = new PageInfo (list); result.put("total", pageInfo.getTotal()); } catch (Exception e) { e.printStackTrace(); return null; } return result; } }
IndexController
package com.app.controller; import static com.app.util.StringUtilsEx.isEmpty; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; import com.app.bean.Movies; import com.app.bean.News; import com.app.bean.Ticket; import com.app.mapper.NewsMapper; import com.app.service.MovieService; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; @Controller public class IndexController { @Autowired private MovieService ms; @Autowired private NewsMapper newsMapper; @RequestMapping("front/index") public ModelAndView index(String moviename){ ModelAndView mav = new ModelAndView(); PageHelper.startPage(1, 10); Listlist = ms.list(moviename); //电影 mav.addObject("movieList",list); mav.addObject("jrpf",ms.queryList("jrpf")); mav.addObject("zsqd",ms.queryList("zsqd")); mav.addObject("hprc",ms.queryList("hprc")); mav.addObject("newsList",ms.queryList("news")); mav.setViewName("front/index.jsp"); return mav; } @RequestMapping("front/detail") public ModelAndView detail(String id){ ModelAndView mav = new ModelAndView(); //根据id获取电影的所有信息 Movies movie = ms.getById(id); //根据id获取所有的电影票 List tickets = ms.getTicketsByMovieId(id); mav.addObject("movie", movie); mav.addObject("tickets", tickets); mav.addObject("jrpf",ms.queryList("jrpf")); mav.addObject("zsqd",ms.queryList("zsqd")); mav.addObject("hprc",ms.queryList("hprc")); mav.addObject("newsList",ms.queryList("news")); mav.setViewName("front/detail.jsp"); return mav; } @RequestMapping("front/detailNews") public ModelAndView detailNews(String id){ ModelAndView mav = new ModelAndView(); //根据id获取电影的所有信息 News news = newsMapper.selectByPrimaryKey(Integer.parseInt(id)); mav.addObject("news", news); mav.addObject("jrpf",ms.queryList("jrpf")); mav.addObject("zsqd",ms.queryList("zsqd")); mav.addObject("hprc",ms.queryList("hprc")); mav.addObject("newsList",ms.queryList("news")); mav.setViewName("front/detailNews.jsp"); return mav; } @RequestMapping("front/result") public ModelAndView result(String moviename,Integer page,Integer rows){ ModelAndView mav = new ModelAndView(); if(isEmpty(page) || isEmpty(rows)) { page = 1; rows = 5; } PageHelper.startPage(page, rows); //根据id获取所有的电影票 List list = ms.list(moviename); mav.addObject("rows",list); PageInfo pageInfo = new PageInfo (list); mav.addObject("total",pageInfo.getTotal()); mav.addObject("page",page); mav.addObject("jrpf",ms.queryList("jrpf")); mav.addObject("zsqd",ms.queryList("zsqd")); mav.addObject("hprc",ms.queryList("hprc")); mav.addObject("newsList",ms.queryList("news")); mav.setViewName("front/result.jsp"); return mav; } }
UserController
package com.app.controller; import static com.app.util.StringUtilsEx.isEmpty; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.app.bean.Movies; import com.app.bean.Users; import com.app.bean.UsersExample; import com.app.bean.UsersExample.Criteria; import com.app.core.ReturnVoCommon; import com.app.mapper.UsersMapper; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import net.sf.json.JSONObject; @Controller @RequestMapping("/user") public class UserController { @Autowired private UsersMapper userMapper; @RequestMapping("/list") @ResponseBody public Maplist(Integer page,Integer rows){ Map result = new HashMap<>(); List list = null; try { if(isEmpty(page) || isEmpty(rows)) { page = 1; rows = 5; } PageHelper.startPage(page, rows); list = userMapper.selectByExample(new UsersExample()); result.put("rows", list); PageInfo pageInfo = new PageInfo (list); result.put("total", pageInfo.getTotal()); } catch (Exception e) { e.printStackTrace(); return null; } return result; } @RequestMapping("/delete") @ResponseBody public Map delete(String id){ Map returnVo = new HashMap (); returnVo.put("code", 0); try{ userMapper.deleteByPrimaryKey(Integer.parseInt(id)); }catch(Exception e){ returnVo.put("code", -1); } return returnVo; } @RequestMapping("/reg") @ResponseBody public ReturnVoCommon reg(Users user,HttpServletRequest request){ ReturnVoCommon vo = new ReturnVoCommon(); UsersExample example = new UsersExample(); Criteria createCriteria = example.createCriteria(); createCriteria.andNameEqualTo(user.getName()); List list = userMapper.selectByExample(example); if(list.size() == 1){ vo.setCode(-1); vo.setErrMsg("用户名存在!"); return vo; } user.setAuth("注册用户"); userMapper.insert(user); return vo; } @RequestMapping("/login") @ResponseBody public ReturnVoCommon login(Users user,HttpServletRequest request){ ReturnVoCommon vo = new ReturnVoCommon(); UsersExample example = new UsersExample(); Criteria createCriteria = example.createCriteria(); createCriteria.andNameEqualTo(user.getName()); createCriteria.andPasswordEqualTo(user.getPassword()); createCriteria.andAuthEqualTo(user.getAuth()); List list = userMapper.selectByExample(example); if(list.size() < 1){ vo.setCode(-1); vo.setErrMsg("用户名或者密码错误!"); return vo; } if(user.getAuth().equals("注册用户")){ vo.setCode(1); request.getSession().setAttribute("currentUser", list.get(0)); }else{ vo.setCode(2); request.getSession().setAttribute("adminUser", list.get(0)); } return vo; } }
到此这篇关于基于Java+SSM实现电影院购票系统的文章就介绍到这了,更多相关Java SSM电影院购票系统内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!