基于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/role")
@Controller
public class RoleController {
private Logger log = LoggerFactory.getLogger(RoleController.class);
@Autowired
private MenuService menuService;
@Autowired
private OperaterLogService operaterLogService;
@Autowired
private RoleService roleService;
/**
* 分页搜索角色列表
* @param model
* @param role
* @param pageBean
* @return
*/
@RequestMapping(value="/list")
public String list(Model model, Role role, PageBean<Role> pageBean){
model.addAttribute("title", "角色列表");
model.addAttribute("name", role.getName());
model.addAttribute("pageBean", roleService.findByName(role, pageBean));
return "admin/role/list";
}
/**
* 角色添加页面
* @param model
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.GET)
public String add(Model model){
List<Menu> findAll = menuService.findAll();
model.addAttribute("topMenus", MenuUtil.getTopMenus(findAll));
model.addAttribute("secondMenus",MenuUtil.getSecondMenus(findAll));
model.addAttribute("thirdMenus",MenuUtil.getThirdMenus(findAll));
return "admin/role/add";
}
/**
* 角色添加表单提交处理
* @param role
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
//判断是否是编辑
if(cinemaHallSession.getId() != null && cinemaHallSession.getId() > 0){
CinemaHallSession findById = cinemaHallSessionService.findById(cinemaHallSession.getId());
cinemaHallSession.setCreateTime(findById.getCreateTime());
}
//生成散场时间
String startTime = cinemaHallSession.getShowDate() + " " + cinemaHallSession.getShowTime();
cinemaHallSession.setStartTime(startTime);
cinemaHallSession.setEndTime(StringUtil.getFormatterDate(startTime, "yyyy-MM-dd HH:mm", Integer.valueOf(cinemaHallSession.getMovie().getTime())));
if(cinemaHallSessionService.isExistHall(cinemaHallSession.getId(),cinemaHallSession.getCinemaHall().getId(), cinemaHallSession.getShowDate(), startTime,cinemaHallSession.getEndTime())){
return Result.error(CodeMsg.ADMIN_CINEMA_HALL_SESSION_SAVE_EXIST);
}
//表示数据合法,可以保存到数据库
if(cinemaHallSessionService.save(cinemaHallSession) == null){
return Result.error(CodeMsg.ADMIN_CINEMA_HALL_SESSION_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 {
cinemaHallSessionService.delete(id);
} catch (Exception e) {
return Result.error(CodeMsg.ADMIN_CINEMA_HALL_SESSION_DELETE_ERROR);
}
return Result.success(true);
}
}
@ResponseBody
public Result<List<CinemaHall>> getCinemaHalls(@RequestParam(name="cid",required=true)Long cid){
return Result.success(cinemaHallService.findAll(cid));
}
}
/**
* 后台用户管理控制器
*
*/
@RequestMapping("/admin/user")
@Controller
public class UserController {
@Autowired
private UserService userService;
@Autowired
private RoleService roleService;
@Autowired
private OperaterLogService operaterLogService;
/**
* 用户列表页面
* @param model
* @param user
* @param pageBean
* @return
*/
@RequestMapping(value="/list")
/**
* 订单列表
* @param model
* @return
*/
@RequestMapping(value="/user-order-list",method=RequestMethod.GET)
public String userOrderList(Model model){
Account account = (Account)SessionUtil.get(SessionConstant.SESSION_ACCOUNT_LOGIN_KEY);
model.addAttribute("orderList", orderService.findAll(account.getId()));
return "home/account/user-order-list";
}
/**
* 用户评价列表
* @param model
* @return
*/
@RequestMapping(value="/user-comment",method=RequestMethod.GET)
public String userComment(Model model,@RequestParam(name="type",defaultValue="0")Integer type){
Account account = (Account)SessionUtil.get(SessionConstant.SESSION_ACCOUNT_LOGIN_KEY);
if(type != 0){
model.addAttribute("cinemaCommentList", cinemaCommentService.findByAccount(account.getId()));
}else{
model.addAttribute("movieCommentList", movieCommentService.findByAccount(account.getId()));
}
model.addAttribute("type", type);
return "home/account/user-comment";
}
/**
* 获取订单子项
* @param sn
* @return
*/
@RequestMapping(value="/get_order_item",method=RequestMethod.POST)
@ResponseBody
public Result<List<OrderItem>> getOrderItem(@RequestParam(name="order_sn",required=true)String sn){
Order order = orderService.find(sn);
if(order == null){
return Result.error(CodeMsg.HOME_ORDER_NO_EXIST);
}
/**
* 前台电影控制器
*
*/
@RequestMapping("/home/movie")
@Controller
public class HomeMovieController {
@Autowired
private MovieService movieService;
@Autowired
private MovieCommentService movieCommentService;
@Autowired
private NewsService newsService;
@Autowired
private CinemaHallSessionService cinemaHallSessionService;
@Autowired
private CinemaService cinemaService;
@Autowired
private CinemaHallSeatService cinemaHallSeatService;
@Value("${movie.select.seat.max.num}")
private Integer selectedSeatMax;//最大选座数
@Autowired
private OrderService orderService;
@Autowired
private OrderItemService orderItemService;
/**
* 电影列表页面
* @param model
* @return
*/
@RequestMapping("/list")
public String list(Model model,@RequestParam(name="type",defaultValue="0") Integer type){
model.addAttribute("movieList", type == 0 ? movieService.findShowList() : movieService.findFutureList());
model.addAttribute("type", type);
model.addAttribute("topNewsList", newsService.findTop());
model.addAttribute("topMoneyMovieList", movieService.findTopMoneyList());
return "home/movie/list";
}
/**
* 电影详情页面
* @param model
* @param id
//放入session
SessionUtil.set(SessionConstant.SESSION_ACCOUNT_LOGIN_KEY, account);
return Result.success(true);
}
/**
* 生成支付记录
* @param payLog
* @return
*/
@RequestMapping(value="/generate_pay_log",method=RequestMethod.POST)
@ResponseBody
public Result<String> generatePayLog(PayLog payLog){
Account account = (Account)SessionUtil.get(SessionConstant.SESSION_ACCOUNT_LOGIN_KEY);
payLog.setAccount(account);
payLog.setSn(StringUtil.generateSn());
payLogService.save(payLog);
account.setBalance(account.getBalance().add(payLog.getMoney()));
accountService.save(account);
return Result.success(null);
}
/**
* 订单列表
* @param model
* @return
*/
@RequestMapping(value="/user-order-list",method=RequestMethod.GET)
public String userOrderList(Model model){
Account account = (Account)SessionUtil.get(SessionConstant.SESSION_ACCOUNT_LOGIN_KEY);
model.addAttribute("orderList", orderService.findAll(account.getId()));
return "home/account/user-order-list";
}
/**
* 用户评价列表
* @param model
* @return
*/
@RequestMapping(value="/user-comment",method=RequestMethod.GET)
public String userComment(Model model,@RequestParam(name="type",defaultValue="0")Integer type){
Account account = (Account)SessionUtil.get(SessionConstant.SESSION_ACCOUNT_LOGIN_KEY);
if(type != 0){
model.addAttribute("cinemaCommentList", cinemaCommentService.findByAccount(account.getId()));
}else{
model.addAttribute("movieCommentList", movieCommentService.findByAccount(account.getId()));
}
CodeMsg validate = ValidateEntityUtil.validate(cinemaHallSession);
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
//判断是否是编辑
if(cinemaHallSession.getId() != null && cinemaHallSession.getId() > 0){
CinemaHallSession findById = cinemaHallSessionService.findById(cinemaHallSession.getId());
cinemaHallSession.setCreateTime(findById.getCreateTime());
}
//生成散场时间
String startTime = cinemaHallSession.getShowDate() + " " + cinemaHallSession.getShowTime();
cinemaHallSession.setStartTime(startTime);
cinemaHallSession.setEndTime(StringUtil.getFormatterDate(startTime, "yyyy-MM-dd HH:mm", Integer.valueOf(cinemaHallSession.getMovie().getTime())));
if(cinemaHallSessionService.isExistHall(cinemaHallSession.getId(),cinemaHallSession.getCinemaHall().getId(), cinemaHallSession.getShowDate(), startTime,cinemaHallSession.getEndTime())){
return Result.error(CodeMsg.ADMIN_CINEMA_HALL_SESSION_SAVE_EXIST);
}
//表示数据合法,可以保存到数据库
if(cinemaHallSessionService.save(cinemaHallSession) == null){
return Result.error(CodeMsg.ADMIN_CINEMA_HALL_SESSION_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 {
cinemaHallSessionService.delete(id);
} catch (Exception e) {
return Result.error(CodeMsg.ADMIN_CINEMA_HALL_SESSION_DELETE_ERROR);
}
return Result.success(true);
}
}
orderAuth.setMac(StringUtil.getMac());
orderAuth.setOrderSn(orderSn);
orderAuth.setPhone(phone);
orderAuthService.save(orderAuth);
AppConfig.ORDER_AUTH = 1;
return Result.success(true);
}
/**
* 清空整个日志
* @return
*/
@RequestMapping(value="/delete_all_operator_log",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> deleteAll(){
operaterLogService.deleteAll();
return Result.success(true);
}
}
/**
* 后台角色管理控制器
*
*/
@RequestMapping("/admin/role")
@Controller
public class RoleController {
private Logger log = LoggerFactory.getLogger(RoleController.class);
@Autowired
private MenuService menuService;
@Autowired
private OperaterLogService operaterLogService;
@Autowired
private RoleService roleService;
/**
* 分页搜索角色列表
* @param model
* @param role
* @param pageBean
* @return
*/
@RequestMapping(value="/list")
public String list(Model model, Role role, PageBean<Role> pageBean){
model.addAttribute("title", "角色列表");
model.addAttribute("name", role.getName());
model.addAttribute("pageBean", roleService.findByName(role, pageBean));
return "admin/role/list";
}
/**
* 角色添加页面
* @param model
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.GET)
}
//判断是否是编辑
if(cinemaHall.getId() != null && cinemaHall.getId() > 0){
CinemaHall findById = cinemaHallService.findById(cinemaHall.getId());
cinemaHall.setCreateTime(findById.getCreateTime());
cinemaHall.setMaxX(findById.getMaxX());
cinemaHall.setMaxY(findById.getMaxY());
}
//表示数据合法,可以保存到数据库
if(cinemaHallService.save(cinemaHall) == null){
return Result.error(CodeMsg.ADMIN_CINEMA_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 {
cinemaHallService.delete(id);
} catch (Exception e) {
return Result.error(CodeMsg.ADMIN_CINEMA_HALL_DELETE_ERROR);
}
return Result.success(true);
}
/**
* 编辑/生成影厅座位
* @param model
* @param id
* @return
*/
@RequestMapping(value="/edit_seat",method=RequestMethod.GET)
public String editSeat(Model model,@RequestParam(name="id",required=true)Long id){
CinemaHall cinemaHall = cinemaHallService.findById(id);
model.addAttribute("cinemaHall", cinemaHall);
List<CinemaHallSeat> findAll = cinemaHallSeatService.findAll(cinemaHall.getId());
model.addAttribute("cinemaHallSeats", findAll.size() > 0 ? findAll : null);
return "admin/cinema_hall/edit_seat";
}
return "admin/system/login";
}
/**
* 用户登录提交表单处理方法
* @param request
* @param user
* @param cpacha
* @return
*/
@RequestMapping(value="/login",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> login(HttpServletRequest request, User user, String cpacha){
if(user == null){
return Result.error(CodeMsg.DATA_ERROR);
}
//用统一验证实体方法验证是否合法
CodeMsg validate = ValidateEntityUtil.validate(user);
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
//表示实体信息合法,开始验证验证码是否为空
if(StringUtils.isEmpty(cpacha)){
return Result.error(CodeMsg.CPACHA_EMPTY);
}
//说明验证码不为空,从session里获取验证码
Object attribute = request.getSession().getAttribute("admin_login");
if(attribute == null){
return Result.error(CodeMsg.SESSION_EXPIRED);
}
//表示session未失效,进一步判断用户填写的验证码是否正确
if(!cpacha.equalsIgnoreCase(attribute.toString())){
return Result.error(CodeMsg.CPACHA_ERROR);
}
//表示验证码正确,开始查询数据库,检验密码是否正确
User findByUsername = userService.findByUsername(user.getUsername());
//判断是否为空
if(findByUsername == null){
return Result.error(CodeMsg.ADMIN_USERNAME_NO_EXIST);
}
//表示用户存在,进一步对比密码是否正确
if(!findByUsername.getPassword().equals(user.getPassword())){
return Result.error(CodeMsg.ADMIN_PASSWORD_ERROR);
}
//表示密码正确,接下来判断用户状态是否可用
if(findByUsername.getStatus() == User.ADMIN_USER_STATUS_UNABLE){
return Result.error(CodeMsg.ADMIN_USER_UNABLE);
* 订单列表
* @param model
* @return
*/
@RequestMapping(value="/user-order-list",method=RequestMethod.GET)
public String userOrderList(Model model){
Account account = (Account)SessionUtil.get(SessionConstant.SESSION_ACCOUNT_LOGIN_KEY);
model.addAttribute("orderList", orderService.findAll(account.getId()));
return "home/account/user-order-list";
}
/**
* 用户评价列表
* @param model
* @return
*/
@RequestMapping(value="/user-comment",method=RequestMethod.GET)
public String userComment(Model model,@RequestParam(name="type",defaultValue="0")Integer type){
Account account = (Account)SessionUtil.get(SessionConstant.SESSION_ACCOUNT_LOGIN_KEY);
if(type != 0){
model.addAttribute("cinemaCommentList", cinemaCommentService.findByAccount(account.getId()));
}else{
model.addAttribute("movieCommentList", movieCommentService.findByAccount(account.getId()));
}
model.addAttribute("type", type);
return "home/account/user-comment";
}
/**
* 获取订单子项
* @param sn
* @return
*/
@RequestMapping(value="/get_order_item",method=RequestMethod.POST)
@ResponseBody
public Result<List<OrderItem>> getOrderItem(@RequestParam(name="order_sn",required=true)String sn){
Order order = orderService.find(sn);
if(order == null){
return Result.error(CodeMsg.HOME_ORDER_NO_EXIST);
}
return Result.success(orderItemService.find(order.getId()));
}
/**
* 删除订单
* @param sn
* @return
*/
@RequestMapping(value="/delete_order",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> deleteOrder(@RequestParam(name="order_sn",required=true)String sn){
Order order = orderService.find(sn);
if(order == null){
address = province.getName();
}
if(city != null){
address += city.getName();
}
cinema.setAddress(address+cinema.getAddress());
}
//表示数据合法,可以保存到数据库
if(cinemaService.save(cinema) == null){
return Result.error(CodeMsg.ADMIN_CINEMA_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 {
cinemaService.delete(id);
} catch (Exception e) {
return Result.error(CodeMsg.ADMIN_CINEMA_DELETE_ERROR);
}
return Result.success(true);
}
/**
* ----------影院评价管理-------------
*/
/**
* 影院评价列表
* @param model
* @param cinemaComment
* @param pageBean
* @return
*/
@RequestMapping(value="/comment_list")
public String list(Model model,CinemaComment cinemaComment,PageBean<CinemaComment> pageBean){
if(menu.getParent().getId() == null){
menu.setParent(null);
}
}
//表示验证都通过,开始添加数据库
if(menuService.save(menu) == null){
Result.error(CodeMsg.ADMIN_MENU_ADD_ERROR);
}
//数据库添加操作成功,记录日志
operaterLogService.add("添加菜单信息【" + menu + "】");
return Result.success(true);
}
/**
* 菜单编辑页面
* @param model
* @param id
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.GET)
public String eidt(Model model,@RequestParam(name="id",required=true)Long id){
List<Menu> findAll = menuService.findAll();
model.addAttribute("title","菜单列表");
model.addAttribute("topMenus",MenuUtil.getTopMenus(findAll));
model.addAttribute("secondMenus",MenuUtil.getSecondMenus(findAll));
model.addAttribute("menu",menuService.find(id));
return "admin/menu/edit";
}
/**
* 菜单编辑页面表单提交处理
* @param request
* @param menu
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> edit(Menu menu){
if(menu == null){
Result.error(CodeMsg.DATA_ERROR);
}
if(menu.getId() == null){
Result.error(CodeMsg.ADMIN_MENU_ID_EMPTY);
}
//用统一验证实体方法验证是否合法
CodeMsg validate = ValidateEntityUtil.validate(menu);
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
if(menu.getParent() != null){
if(menu.getParent().getId() == null){
menu.setParent(null);
}
* @param id
* @return
*/
@RequestMapping("/select_seat")
public String selectSeat(Model model,@RequestParam(name="id",required=true) Long id){
CinemaHallSession cinemaHallSession = cinemaHallSessionService.findById(id);
model.addAttribute("cinemaHallSession", cinemaHallSession);
model.addAttribute("cinemaHallSeatList", cinemaHallSeatService.findAll(cinemaHallSession.getCinemaHall().getId()));
model.addAttribute("selectedSeatMax", selectedSeatMax);
List<Order> findByCinemaHallSession = orderService.findByCinemaHallSession(id);
model.addAttribute("orderSeatList", JSONArray.toJSONString(orderItemService.findOrderItemSeatIds(findByCinemaHallSession)));
return "home/movie/select_seat";
}
/**
* 获取指定电影、指定影院、指定时间下的场次
* @param model
* @param mid
* @param cid
* @param showDate
* @return
*/
@RequestMapping("/get_show_session")
public String getShowSession(Model model,
@RequestParam(name="mid",required=true) Long mid,
@RequestParam(name="cid",required=true) Long cid,
@RequestParam(name="showDate",required=true) String showDate){
model.addAttribute("cinemaHallSessionList", cinemaHallSessionService.findByMovieIdAndCinemaIdAndShowDate(mid, cid, showDate));
return "home/movie/get_show_session";
}
/**
* 统计电影上映场次
* @param movieId
* @return
*/
@RequestMapping("/get_show_stats")
@ResponseBody
public Result<List<Integer>> getShowStats(@RequestParam(name="mid",required=true) Long movieId) {
List<Integer> ret = new ArrayList<Integer>();
List<Integer> showTotal = cinemaHallSessionService.getShowTotal(movieId);
if(showTotal == null || showTotal.size() <= 0){
ret.add(0);
ret.add(0);
return Result.success(ret);
}
//获取文件后缀
String suffix = originalFilename.substring(originalFilename.lastIndexOf("."), originalFilename.length());
if (!uploadPhotoSufix.contains(suffix.toLowerCase())) {
return Result.error(CodeMsg.UPLOAD_PHOTO_SUFFIX_ERROR);
}
if (photo.getSize() / 1024 > uploadPhotoMaxSize) {
CodeMsg codeMsg = CodeMsg.UPLOAD_PHOTO_ERROR;
codeMsg.setMsg("图片大小不能超过" + (uploadPhotoMaxSize / 1024) + "M");
return Result.error(codeMsg);
}
//准备保存文件
File filePath = new File(uploadPhotoPath);
if (!filePath.exists()) {
//若不存在文件夹,则创建一个文件夹
filePath.mkdir();
}
filePath = new File(uploadPhotoPath + "/" + StringUtil.getFormatterDate(new Date(), "yyyyMMdd"));
//判断当天日期的文件夹是否存在,若不存在,则创建
if (!filePath.exists()) {
//若不存在文件夹,则创建一个文件夹
filePath.mkdir();
}
String filename = StringUtil.getFormatterDate(new Date(), "yyyyMMdd") + "/" + System.currentTimeMillis() + suffix;
try {
photo.transferTo(new File(uploadPhotoPath + "/" + filename));
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
log.info("图片上传成功,保存位置:" + uploadPhotoPath + filename);
return Result.success(filename);
}
/**
* 上传视频
*
* @param video
* @return
*/
@RequestMapping(value = "/upload_video", method = RequestMethod.POST)
String paramToken = DESUtil.encrypt(orderSn, mac+"#"+orderSn+"#"+phone);
headerParaMap.put("paramToken", paramToken);
String timeToken = DESUtil.encrypt("muyi_ylrc", System.currentTimeMillis()+"");
headerParaMap.put("timeToken", timeToken);
String sendPost = HttpUtil.sendPost("http://120.25.120.129:8081/order_auth/verify",headerParaMap,"orderSn="+orderSn+"&phone="+phone+"&mac="+mac);
JSONObject parseObject = JSONObject.parseObject(sendPost);
if(parseObject.getIntValue("code") != CodeMsg.SUCCESS.getCode()){
return false;
}
return true;
}
public static String readFileToString(File file){
String string = "";
if(file != null){
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line = null;
while ((line = br.readLine()) != null) {
string += line;
}
br.close();
} catch (Exception e) {
// TODO: handle exception
}
}
return string;
}
}
/**
* 后台菜单管理控制器
*
*/