影院订票系统java,基于ssm的电影订票系统
目录
项目介绍效果图展示实现逻辑代码电影控制器新闻控制器索引控制器
项目介绍
基于Spring,SpringMVC,Mybatis开发实现。
数据库用的是MySQL5.5。
开发工具用的Eclipse Tomcat7,JDK1.7-1.8皆可。
效果图展示
首页
电影详情页
购票
登录注册页面
后台管理页面
电影信息列表
添加电影信息
电影票管理
订单管理
热点新闻管理
实现逻辑代码
抽出一些核心代码,如有病菌和问题,欢迎指出。
MovieController
包com。app。控制器;导入Java。util。hashmap导入Java。util。列表;导入Java。util。地图;导入org。spring框架。豆子。工厂。注释。自动连线;导入org。spring框架。刻板印象。控制器;导入org。spring框架。网络。绑定。注释。请求映射;导入org。spring框架。网络。绑定。注释。响应正文;导入org。spring框架。网络。servlet。模型和视图;导入com。app。比恩。电影;导入com。app。比恩。订单;导入com。app。比恩。票;导入com。app。服务。电影服务;导入com。app。util。stringutilsex导入com。github。页面助手。页面助手;导入com。github。页面助手。pageinfo导入静态com。app。util。字符串utilsex。*;@控制器@请求映射(/movie )公共类电影控制器{ @ autowired私人电影服务ms;@ request mapping(/list order )@ ResponseBodypublic MapString,Object listOrder(整数页,整数行){MapString,Object result=new HashMap();ListOrders list=null请尝试{ if(isEmpty(page) isEmpty(rows)){ page=1;行数=5;}PageHelper.startPage(page,rows);list=ms . list order();result.put(rows ,list);PageInfoOrders pageInfo=new PageInfoOrders(list);result.put(total ,pagenfo。gettotal());} catch(Exception e){ e . printstacktrace();返回null}返回结果;}//根据电影票身份生成订单@请求映射(/add order )@ ResponseBodypublic MapString,Object ad
dOrder(String id){Map<String,Object> returnVo = new HashMap<String, Object>();returnVo.put("code", 0);try{ms.addOrder(id);}catch(Exception e){returnVo.put("code", -1);}return returnVo;}@RequestMapping("/getById")@ResponseBodypublic Movies getById(String id){returnms.getById(id);}@RequestMapping("/createTickets")@ResponseBodypublic Map<String,Object> createTickets(String id){Map<String,Object> returnVo = new HashMap<String, Object>();returnVo.put("code", 0);//先检查这个id的电影是否已经生成了电影票List<Ticket> 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")@ResponseBodypublic Map<String,Object> update(String id,String column){Map<String,Object> returnVo = new HashMap<String, Object>();returnVo.put("code", 0);try{ms.update(id,column);}catch(Exception e){returnVo.put("code", -1);}return returnVo;}@RequestMapping("/delete")@ResponseBodypublic Map<String,Object> delete(String id){Map<String,Object> returnVo = new HashMap<String, Object>();returnVo.put("code", 0);try{ms.delete(id);}catch(Exception e){returnVo.put("code", -1);}return returnVo;}@RequestMapping("/add")@ResponseBodypublic Map<String,Object> add(Movies movie){Map<String,Object> returnVo = new HashMap<String, Object>();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")@ResponseBodypublic Map<String,Object> list(String moviename,Integer page,Integer rows){Map<String,Object> result = new HashMap<>();List<Movies> 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<Movies> pageInfo = new PageInfo<Movies>(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 { @Autowiredprivate NewsService service;@RequestMapping("/getById")@ResponseBodypublic News getById(String id){returnservice.getById(id);}@RequestMapping("/delete")@ResponseBodypublic Map<String,Object> delete(String id){Map<String,Object> returnVo = new HashMap<String, Object>();returnVo.put("code", 0);try{service.delete(id);}catch(Exception e){returnVo.put("code", -1);}return returnVo;}@RequestMapping("/add")@ResponseBodypublic Map<String,Object> add(News news){Map<String,Object> returnVo = new HashMap<String, Object>();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")@ResponseBodypublic Map<String,Object> list(String newsname,Integer page,Integer rows){Map<String,Object> result = new HashMap<>();List<News> 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<News> pageInfo = new PageInfo<News>(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; @Controllerpublic class IndexController { @Autowiredprivate MovieService ms;@Autowiredprivate NewsMapper newsMapper;@RequestMapping("front/index")public ModelAndView index(String moviename){ModelAndView mav = new ModelAndView();PageHelper.startPage(1, 10);List<Movies> list = 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<Ticket> 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<Movies> pageInfo = new PageInfo<Movies>(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 {@Autowiredprivate UsersMapper userMapper;@RequestMapping("/list")@ResponseBodypublic Map<String,Object> list(Integer page,Integer rows){Map<String,Object> result = new HashMap<>();List<Users> 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<Users> pageInfo = new PageInfo<Users>(list);result.put("total", pageInfo.getTotal());} catch (Exception e) {e.printStackTrace();return null;}return result;}@RequestMapping("/delete")@ResponseBodypublic Map<String,Object> delete(String id){Map<String,Object> returnVo = new HashMap<String, Object>();returnVo.put("code", 0);try{userMapper.deleteByPrimaryKey(Integer.parseInt(id));}catch(Exception e){returnVo.put("code", -1);}return returnVo;}@RequestMapping("/reg")@ResponseBodypublic ReturnVoCommon reg(Users user,HttpServletRequest request){ReturnVoCommon vo = new ReturnVoCommon();UsersExample example = new UsersExample();Criteria createCriteria = example.createCriteria();createCriteria.andNameEqualTo(user.getName());List<Users> list = userMapper.selectByExample(example);if(list.size() == 1){vo.setCode(-1);vo.setErrMsg("用户名存在!");return vo;}user.setAuth("注册用户");userMapper.insert(user);return vo;}@RequestMapping("/login")@ResponseBodypublic 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<Users> 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电影院购票系统内容请搜索盛行IT以前的文章或继续浏览下面的相关文章希望大家以后多多支持盛行IT!
郑重声明:本文由网友发布,不代表盛行IT的观点,版权归原作者所有,仅为传播更多信息之目的,如有侵权请联系,我们将第一时间修改或删除,多谢。