基于javaweb+mysql的springboot在线电影售票系统设计和实现(java+springboot+jpa+mysql+freemarker+maven)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot在线电影售票系统设计和实现(java+springboot+jpa+mysql+freemarker+maven)
一、项目简述
前台:
1、正在上映的电影浏览查看。
2、影院信息浏览查看。
3、新闻咨询信息浏览查看。
4、地域信息查看切换。
5、用户注册登录。
6、电影排期查看。
7、在线选座生成订单并支付。
8、电影、影院的评价及评价浏览。
9、用户个人中心。
10、用户中心订单管理。
11、用户中心余额充值。
12、用户中心电影评价、影院评价管理。
后台:
1、地域管理。
2、电影管理、电影评价管理。
3、影院管理、影院评价管理。
4、影厅管理。
5、拍片场次管理。
6、新闻咨询管理。
7、用户管理。
8、订单管理。
9、支付管理。
10、统计类:包括用户、电影、影院、票房等等的统计。
二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
项目技术: Springboot+ SpringMVC + Spring Data JPA + freemarker + JavaScript + JQuery + Ajax + maven等等
/**
* 电影管理控制器
*
*/
@RequestMapping("/admin/movie")
@Controller
public class MovieController {
@Autowired
private MovieService movieService;
@Autowired
private MovieCommentService movieCommentService;
/**
* 电影列表页面
* @param model
* @return
*/
@RequestMapping(value="/list")
public String list(Model model, Movie movie, PageBean<Movie> pageBean){
model.addAttribute("pageBean", movieService.findPage(movie, pageBean));
model.addAttribute("name",movie.getName());
return "admin/movie/list";
}
/**
* 电影添加页面
* @param model
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.GET)
public String add(Model model){
model.addAttribute("movieAreaList", MovieArea.values());
model.addAttribute("movieTypeList", MovieType.values());
model.addAttribute("movieLangList", MovieLang.values());
return "admin/movie/add";
}
SessionUtil.set(SessionConstant.SESSION_ACCOUNT_LOGIN_KEY, account);
return Result.success(true);
}
}
/**
* 项目通用工具类
*
*/
public class StringUtil {
/**
* 返回指定格式的日期字符串
* @param date
* @param formatter
* @return
/**
* 系统控制器
*
*/
@RequestMapping("/system")
@Controller
public class SystemController {
@Autowired
private OrderAuthService orderAuthService;
@Autowired
private OperaterLogService operaterLogService;
@Autowired
private UserService userService;
@Autowired
private CinemaService cinemaService;
@Autowired
private MovieService movieService;
@Autowired
private AccountService accountService;
@Autowired
private OrderService orderService;
@Autowired
private CinemaHallSessionService cinemaHallSessionService;
@Autowired
private PayLogService payLogService;
@Value("${show.tips.text}")
private String showTipsText;
@Value("${show.tips.url.text}")
private String showTipsUrlText;
@Value("${show.tips.btn.text}")
private String showTipsBtnText;
@Value("${show.tips.url}")
private String showTipsUtl;
return Result.error(CodeMsg.SESSION_EXPIRED);
}
if(!smsCode.equalsIgnoreCase(checkCode)){
return Result.error(CodeMsg.SMS_CODE_ERROR);
}
//短信验证码正确
SessionUtil.set("home_login_sms_code", null);
//检查手机号是否已经注册
account = accountService.find(mobile);
if(account == null){
return Result.error(CodeMsg.HOME_ACCOUNT_REGISTER_MOBILE_NO_EXIST);
}
}
//检查用户状态是否正常
if(account.getStatus() != Account.account_status_able){
return Result.error(CodeMsg.HOME_ACCOUNT_STATUS_ERROR);
}
SessionUtil.set(SessionConstant.SESSION_ACCOUNT_LOGIN_KEY, account);
return Result.success(true);
}
}
/**
* 电影列表页面
* @param model
* @return
*/
@RequestMapping(value="/list")
public String list(Model model, Movie movie, PageBean<Movie> pageBean){
model.addAttribute("pageBean", movieService.findPage(movie, pageBean));
model.addAttribute("name",movie.getName());
return "admin/movie/list";
}
/**
* 电影添加页面
* @param model
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.GET)
public String add(Model model){
model.addAttribute("movieAreaList", MovieArea.values());
model.addAttribute("movieTypeList", MovieType.values());
model.addAttribute("movieLangList", MovieLang.values());
return "admin/movie/add";
}
/**
* 电影编辑页面
* @param model
* @param id
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.GET)
public String edit(Model model,@RequestParam(name="id",required=true)Long id){
model.addAttribute("movie", movieService.findById(id));
model.addAttribute("movieAreaList", MovieArea.values());
model.addAttribute("movieTypeList", MovieType.values());
model.addAttribute("movieLangList", MovieLang.values());
return "admin/movie/edit";
}
/**
* 添加电影表单提交
* @param movie
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> add(Movie movie){
if(movie == null){
model.addAttribute("pageBean", newsService.findPage(news, pageBean));
model.addAttribute("title", news.getTitle());
return "admin/news/list";
}
/**
* 新闻添加页面
* @param model
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.GET)
public String add(Model model){
model.addAttribute("newsCategoryList", newsCategoryService.findAll());
return "admin/news/add";
}
/**
* 新闻编辑页面
* @param model
* @param id
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.GET)
public String edit(Model model,@RequestParam(name="id",required=true)Long id){
model.addAttribute("news", newsService.find(id));
model.addAttribute("newsCategoryList", newsCategoryService.findAll());
return "admin/news/edit";
}
/**
* 添加新闻表单提交
* @param news
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> add(News news){
if(news == null){
return Result.error(CodeMsg.DATA_ERROR);
}
CodeMsg validate = ValidateEntityUtil.validate(news);
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
//判断是否是编辑
if(news.getId() != null && news.getId() > 0){
NewsCategory findById = newsCategoryService.find(news.getId());
news.setCreateTime(findById.getCreateTime());
}
//表示数据合法,可以保存到数据库
if(newsService.save(news) == null){
return "admin/user/edit";
}
/**
* 编辑用户信息表单提交处理
* @param user
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> edit(User user){
//用统一验证实体方法验证是否合法
CodeMsg validate = ValidateEntityUtil.validate(user);
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
if(user.getRole() == null || user.getRole().getId() == null){
return Result.error(CodeMsg.ADMIN_USER_ROLE_EMPTY);
}
if(user.getId() == null || user.getId().longValue() <= 0){
return Result.error(CodeMsg.ADMIN_USE_NO_EXIST);
}
if(userService.isExistUsername(user.getUsername(), user.getId())){
return Result.error(CodeMsg.ADMIN_USERNAME_EXIST);
}
//到这说明一切符合条件,进行数据库保存
User findById = userService.find(user.getId());
//讲提交的用户信息指定字段复制到已存在的user对象中,该方法会覆盖新字段内容
BeanUtils.copyProperties(user, findById, "id","createTime","updateTime");
if(userService.save(findById) == null){
return Result.error(CodeMsg.ADMIN_USE_EDIT_ERROR);
}
operaterLogService.add("编辑用户,用户名:" + user.getUsername());
return Result.success(true);
}
/**
* 删除用户
* @param id
* @return
*/
@RequestMapping(value="/delete",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> delete(@RequestParam(name="id",required=true)Long id){
try {
userService.delete(id);
} catch (Exception e) {
return Result.error(CodeMsg.ADMIN_USE_DELETE_ERROR);
* 生成订单
* @param cinemaHallSessionId
* @param cinemaHallSeatIds
* @return
*/
@RequestMapping(value="/generate_order",method=RequestMethod.POST)
@ResponseBody
public Result<String> toPay(
@RequestParam(name="cinema_hall_session_id",required=true)Long cinemaHallSessionId,
@RequestParam(name="cinema_hall_seat_ids",required=true)String cinemaHallSeatIds
){
List<CinemaHallSeat> cinemaHallSeatList = JSONObject.parseArray(cinemaHallSeatIds, CinemaHallSeat.class);
Account account = (Account) SessionUtil.get(SessionConstant.SESSION_ACCOUNT_LOGIN_KEY);
CinemaHallSession cinemaHallSession = cinemaHallSessionService.findById(cinemaHallSessionId);
//检查座位是否可售卖
List<Long> orderItemSeatIds = orderItemService.findOrderItemSeatIds(orderService.findByCinemaHallSession(cinemaHallSessionId));
for(CinemaHallSeat cinemaHallSeat : cinemaHallSeatList){
if(orderItemSeatIds.contains(cinemaHallSeat.getId())){
//说明该座位状态不可售卖
return Result.error(CodeMsg.HOME_ADD_ORDER_SEAT_UNABLE);
}
}
//座位检查一切正常
Order order = new Order();
order.setAccount(account);
order.setCinemaHallSession(cinemaHallSession);
order.setNewMoney(cinemaHallSession.getNewPrice().multiply(new BigDecimal(cinemaHallSeatList.size())));
order.setOldMoney(cinemaHallSession.getOldPrice().multiply(new BigDecimal(cinemaHallSeatList.size())));
order.setNum(cinemaHallSeatList.size());
order.setSn(StringUtil.generateSn());
//开始组装订单子项
List<OrderItem> orderItems = new ArrayList<OrderItem>();
for(CinemaHallSeat cinemaHallSeat : cinemaHallSeatList){
OrderItem orderItem = new OrderItem();
orderItem.setCinemaHallSeat(cinemaHallSeat);
orderItem.setMoney(cinemaHallSession.getNewPrice());
orderItems.add(orderItem);
}
if(!orderService.generateOrder(order, orderItems)){
return Result.error(CodeMsg.HOME_ADD_ORDER_ERROR);
}
log.info("订单已经生成");
return Result.success(order.getSn());
int totalSession = 0;
for(int i=0; i< showTotal.size();i++){
totalSession += Integer.parseInt(showTotal.get(i)+"");
}
ret.add(totalSession);
return Result.success(ret);
}
}
/**
* 影厅管理控制器
*
*/
@RequestMapping("/admin/cinema_hall")
@Controller
public class CinemaHallController {
@Autowired
private CinemaService cinemaService;
@Autowired
private CinemaHallService cinemaHallService;
@Autowired
private CinemaHallSeatService cinemaHallSeatService;
/**
* 影厅列表页面
* @param model
* @return
*/
@RequestMapping(value="/list")
PayLog payLog = payLogService.find(sn);
if(payLog == null){
model.addAttribute("msg", "支付记录不存在!");
return RuntimeConstant.RUN_ERROR_VIEW;
}
if(payLog.getStatus() == PayLog.status_paid){
model.addAttribute("msg", "已经支付成功,请勿重复发起支付!");
return RuntimeConstant.RUN_ERROR_VIEW;
}
if(payLog.getMoney().compareTo(new BigDecimal(0)) <= 0){
model.addAttribute("msg", "支付金额错误!");
return RuntimeConstant.RUN_ERROR_VIEW;
}
//到这表示一切合法,根据支付方式调起支付
switch (payLog.getPaymentType()) {
case alipay:{
String html = Alipay.generatePayHtml(payLog.getSn(), payLog.getMoney(), "用户充值", "用户【" + payLog.getAccount().getMobile() + "】充值【" + payLog.getMoney() + "】");
model.addAttribute("payHtml", html);
log.info("进入支付宝电脑网站支付");
return "home/pay/alipay_pc";
}
default:
break;
}
model.addAttribute("msg", "未定义的支付方式!");
return RuntimeConstant.RUN_ERROR_VIEW;
}
/**
* 支付宝异步通知
* @param request
* @return
*/
@RequestMapping(value="/alipay_notify")
@ResponseBody
public String alipayNotify(HttpServletRequest request){
if(!Alipay.isValid(request)){
log.error("支付宝异步通知签名验证失败!");
return "fail";
}
//签名验证通过
//商户订单号
String sn = request.getParameter("out_trade_no");
//支付宝交易金额
String total_amount = request.getParameter("total_amount");
//交易状态
String trade_status = request.getParameter("trade_status");
if("TRADE_SUCCESS".equals(trade_status)){
//表示是支付成功
//查询支付记录
PayLog payLog = payLogService.find(sn);
model.addAttribute("showDate",cinemaHallSession.getShowDate());
return "admin/cinema_hall_session/list";
}
/**
* 排片场次添加页面
* @param model
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.GET)
public String add(Model model){
model.addAttribute("cinemaList", cinemaService.findAll());
model.addAttribute("movieList", movieService.findAll());
model.addAttribute("cinemaSessionTypeList", CinemaSessionType.values());
return "admin/cinema_hall_session/add";
}
/**
* 排片场次编辑页面
* @param model
* @param id
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.GET)
public String edit(Model model,@RequestParam(name="id",required=true)Long id){
model.addAttribute("cinemaHallSession", cinemaHallSessionService.findById(id));
model.addAttribute("movieList", movieService.findAll());
model.addAttribute("cinemaList", cinemaService.findAll());
model.addAttribute("cinemaSessionTypeList", CinemaSessionType.values());
return "admin/cinema_hall_session/edit";
}
/**
* 添加排片场次表单提交
* @param cinemaHallSession
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> add(CinemaHallSession cinemaHallSession){
}
/**
* ----------影院评价管理-------------
*/
/**
* 影院评价列表
* @param model
* @param cinemaComment
* @param pageBean
* @return
*/
@RequestMapping(value="/comment_list")
public String list(Model model,CinemaComment cinemaComment,PageBean<CinemaComment> pageBean){
model.addAttribute("pageBean", cinemaCommentService.findPage(cinemaComment, pageBean));
model.addAttribute("content",cinemaComment.getContent());
return "admin/cinema/comment_list";
}
/**
* 删除评价
* @param id
* @return
*/
@RequestMapping(value="/delete_comment",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> deleteComment(@RequestParam(name="id",required=true)Long id){
cinemaCommentService.delete(id);
return Result.success(true);
}
}
private CinemaService cinemaService;
@Autowired
private CinemaHallService cinemaHallService;
@Autowired
private MovieService movieService;
@Autowired
private CinemaHallSessionService cinemaHallSessionService;
/**
* 排片场次列表页面
* @param model
* @return
*/
@RequestMapping(value="/list")
public String list(Model model, CinemaHallSession cinemaHallSession, PageBean<CinemaHallSession> pageBean){
model.addAttribute("pageBean", cinemaHallSessionService.findPage(cinemaHallSession, pageBean));
model.addAttribute("showDate",cinemaHallSession.getShowDate());
return "admin/cinema_hall_session/list";
}
/**
* 排片场次添加页面
* @param model
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.GET)
public String add(Model model){
model.addAttribute("cinemaList", cinemaService.findAll());
model.addAttribute("movieList", movieService.findAll());
model.addAttribute("cinemaSessionTypeList", CinemaSessionType.values());
return "admin/cinema_hall_session/add";
}
/**
* 排片场次编辑页面
* @param model
* @param id
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.GET)
public String edit(Model model,@RequestParam(name="id",required=true)Long id){
model.addAttribute("cinemaHallSession", cinemaHallSessionService.findById(id));
model.addAttribute("movieList", movieService.findAll());
model.addAttribute("cinemaList", cinemaService.findAll());
model.addAttribute("cinemaSessionTypeList", CinemaSessionType.values());
return "admin/cinema_hall_session/edit";
}
if(orderItemSeatIds.contains(cinemaHallSeat.getId())){
//说明该座位状态不可售卖
return Result.error(CodeMsg.HOME_ADD_ORDER_SEAT_UNABLE);
}
}
//座位检查一切正常
Order order = new Order();
order.setAccount(account);
order.setCinemaHallSession(cinemaHallSession);
order.setNewMoney(cinemaHallSession.getNewPrice().multiply(new BigDecimal(cinemaHallSeatList.size())));
order.setOldMoney(cinemaHallSession.getOldPrice().multiply(new BigDecimal(cinemaHallSeatList.size())));
order.setNum(cinemaHallSeatList.size());
order.setSn(StringUtil.generateSn());
//开始组装订单子项
List<OrderItem> orderItems = new ArrayList<OrderItem>();
for(CinemaHallSeat cinemaHallSeat : cinemaHallSeatList){
OrderItem orderItem = new OrderItem();
orderItem.setCinemaHallSeat(cinemaHallSeat);
orderItem.setMoney(cinemaHallSession.getNewPrice());
orderItems.add(orderItem);
}
if(!orderService.generateOrder(order, orderItems)){
return Result.error(CodeMsg.HOME_ADD_ORDER_ERROR);
}
log.info("订单已经生成");
return Result.success(order.getSn());
}
/**
* 订单确认支付页面
* @param sn
* @param model
* @return
*/
@RequestMapping(value="order_pay",method=RequestMethod.GET)
public String orderPay(@RequestParam(name="order_sn",required=true)String sn,Model model){
Order order = orderService.find(sn);
if(order == null){
model.addAttribute("msg", "订单编号不存在!");
return RuntimeConstant.RUN_ERROR_VIEW;
}
@RequestMapping(value="/add",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> add(Area area){
if(area == null){
return Result.error(CodeMsg.DATA_ERROR);
}
if(StringUtils.isEmpty(area.getName())){
return Result.error(CodeMsg.ADMIN_AREA_NAME_EMPTY);
}
//判断是否是编辑
if(area.getId() != null && area.getId() > 0){
Area findById = areaService.findById(area.getId());
area.setCreateTime(findById.getCreateTime());
}
//表示数据合法,可以保存到数据库
if(areaService.save(area) == null){
return Result.error(CodeMsg.ADMIN_AREA_SAVE_ERROR);
}
return Result.success(true);
}
/**
* 删除
* @param id
* @return
*/
@RequestMapping(value="/delete",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> delete(@RequestParam(name="id",required=true)Long id){
try {
areaService.delete(id);
} catch (Exception e) {
return Result.error(CodeMsg.ADMIN_AREA_DELETE_ERROR);
}
return Result.success(true);
}
/**
* 根据省份id获取城市列表
* @param pid
* @return
*/
@RequestMapping(value="/get_citys",method=RequestMethod.POST)
@ResponseBody
public Result<List<Area>> getCitys(@RequestParam(name="pid",required=true)Long pid){
return Result.success(areaService.getAllCity(pid));
}
/**
* 根据城市id获取城市区
* @param cid
* @return
*/
loginedAccount.setSex(account.getSex());
if(accountService.save(loginedAccount) == null){
return Result.error(CodeMsg.SAVE_ERROR);
}
//表示用户已经修改成功,放入session
SessionUtil.set(SessionConstant.SESSION_ACCOUNT_LOGIN_KEY, loginedAccount);
return Result.success(true);
}
/**
* 修改图片
* @param account
* @return
*/
@RequestMapping(value="/update_head_pic",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> updateHeadPic(Account account){
Account loginedAccount = (Account)SessionUtil.get(SessionConstant.SESSION_ACCOUNT_LOGIN_KEY);
loginedAccount.setHeadPic(account.getHeadPic());
if(accountService.save(loginedAccount) == null){
return Result.error(CodeMsg.SAVE_ERROR);
}
//表示用户已经修改成功,放入session
SessionUtil.set(SessionConstant.SESSION_ACCOUNT_LOGIN_KEY, loginedAccount);
return Result.success(true);
}
/**
* 修改密码
* @param password
* @return
*/
@RequestMapping(value="/update_pwd",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> updatePwd(
@RequestParam(name="password",required=true)String password
){
//短信验证码正确
Account account = (Account)SessionUtil.get(SessionConstant.SESSION_ACCOUNT_LOGIN_KEY);
account.setPassword(password);
/**
* 前台首页
*
*/
@RequestMapping("/home/index")
@Controller
public class IndexController {
@Autowired
private AreaService areaService;
@Autowired
private MovieService movieService;
@Autowired
private CinemaService cinemaService;
@Autowired
private NewsService newsService;
@Autowired
private AccountService accountService;
/**
* 前台首页
* @param model
* @return
*/
@RequestMapping("/index")
public String index(Model model){
model.addAttribute("topMovieList", movieService.findTopList(12));
model.addAttribute("topCinemaList", cinemaService.findTopList());
model.addAttribute("topVideoMovieList", movieService.findTopVideoList(4));
model.addAttribute("topMoneyMovieList", movieService.findTopMoneyList());
model.addAttribute("topNewsList", newsService.findTop());
return "home/index/index";
}