热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Java实战之电影在线观看系统的实现

本文介绍了Java实战之电影在线观看系统的实现过程。首先对项目进行了简述,然后展示了系统的效果图。接着介绍了系统的核心代码,包括后台用户管理控制器、电影管理控制器和前台电影控制器。最后对项目的环境配置和使用的技术进行了说明,包括JSP、Spring、SpringMVC、MyBatis、html、css、JavaScript、JQuery、Ajax、layui和maven等。

一、项目简述

环境配置:

Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)

项目技术:

JSP +Spring + SpringMVC + MyBatis + html+ css + Javascript + JQuery + Ajax + layui+ maven等等。

二、效果图展示

三、核心代码

后台用户管理控制器

/**
 * 后台用户管理控制器
 * @author yy
 *
 */
@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")
	public String list(Model model, User user, PageBean pageBean){
		model.addAttribute("title", "用户列表");
		model.addAttribute("username", user.getUsername());
		model.addAttribute("pageBean", userService.findList(user, pageBean));
		return "admin/user/list";
	}
	
	/**
	 * 新增用户页面
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/add",method=RequestMethod.GET)
	public String add(Model model){
		model.addAttribute("roles", roleService.findAll());
		return "admin/user/add";
	}
	
	/**
	 * 用户添加表单提交处理
	 * @param user
	 * @return
	 */
	@RequestMapping(value="/add",method=RequestMethod.POST)
	@ResponseBody
	public Result add(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(userService.isExistUsername(user.getUsername(), 0l)){
			return Result.error(CodeMsg.ADMIN_USERNAME_EXIST);
		}
		//到这说明一切符合条件,进行数据库新增
		if(userService.save(user) == null){
			return Result.error(CodeMsg.ADMIN_USE_ADD_ERROR);
		}
		operaterLogService.add("添加用户,用户名:" + user.getUsername());
		return Result.success(true);
	}
	
	/**
	 * 用户编辑页面
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/edit",method=RequestMethod.GET)
	public String edit(Model model,@RequestParam(name="id",required=true)Long id){
		model.addAttribute("roles", roleService.findAll());
		model.addAttribute("user", userService.find(id));
		return "admin/user/edit";
	}
	
	/**
	 * 编辑用户信息表单提交处理
	 * @param user
	 * @return
	 */
	@RequestMapping(value="/edit",method=RequestMethod.POST)
	@ResponseBody
	public Result 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 delete(@RequestParam(name="id",required=true)Long id){
		try {
			userService.delete(id);
		} catch (Exception e) {
			return Result.error(CodeMsg.ADMIN_USE_DELETE_ERROR);
		}
		operaterLogService.add("添加用户,用户ID:" + id);
		return Result.success(true);
	}
}

电影管理控制器

/**
 * 电影管理控制器
 * @author yy
 *
 */
@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 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 add(Movie movie){
		if(movie == null){
			return Result.error(CodeMsg.DATA_ERROR);
		}
		CodeMsg validate = ValidateEntityUtil.validate(movie);
		if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
			return Result.error(validate);
		}
		//判断是否是编辑
		if(movie.getId() != null && movie.getId() > 0){
			Movie findById = movieService.findById(movie.getId());
			movie.setCreateTime(findById.getCreateTime());
			movie.setRate(findById.getRate());
			movie.setRateCount(findById.getRateCount());
			movie.setTotalMoney(findById.getTotalMoney());
		}
		//表示数据合法,可以保存到数据库
		if(movieService.save(movie) == 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 delete(@RequestParam(name="id",required=true)Long id){
		try {
			movieService.delete(id);
		} catch (Exception e) {
			return Result.error(CodeMsg.ADMIN_MOVIE_DELETE_ERROR);
		}
		return Result.success(true);
	}
	
	
	/**
	 * ----------电影评价管理-------------
	 */
	/**
	 * 电影评价列表
	 * @param model
	 * @param movieComment
	 * @param pageBean
	 * @return
	 */
	@RequestMapping(value="/comment_list")
	public String list(Model model,MovieComment movieComment,PageBean pageBean){
		model.addAttribute("pageBean", movieCommentService.findPage(movieComment, pageBean));
		model.addAttribute("content",movieComment.getContent());
		return "admin/movie/comment_list";
	}
	
	/**
	 * 删除评价
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/delete_comment",method=RequestMethod.POST)
	@ResponseBody
	public Result deleteComment(@RequestParam(name="id",required=true)Long id){
		movieCommentService.delete(id);
		return Result.success(true);
	}
}

前台电影控制器

/**
 * 前台电影控制器
 * @author yy
 *
 */
@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
	 * @return
	 */
	@RequestMapping("/detail")
	public String detail(Model model,@RequestParam(name="id",required=true) Long id){
		model.addAttribute("movie", movieService.findById(id));
		model.addAttribute("topMovieList", movieService.findTopList(5));
		model.addAttribute("distinctCinemaHallSessionList", cinemaHallSessionService.findDistinctCinemaByMovieId(id));
		model.addAttribute("distinctShowDateCinemaHallSessionList", cinemaHallSessionService.findDistinctShowDateByMovieId(id));
		model.addAttribute("commentList", movieCommentService.findByMovie(id));
		return "home/movie/detail";
	}
	
	/**
	 * 选座页面
	 * @param model
	 * @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 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> getShowStats(@RequestParam(name="mid",required=true) Long movieId) {
		List ret = new ArrayList();
		List showTotal = cinemaHallSessionService.getShowTotal(movieId);
		if(showTotal == null || showTotal.size() <= 0){
			ret.add(0);
			ret.add(0);
			return Result.success(ret);
		}
		ret.add(showTotal.size());//上映的影院数
		//计算场次数
		int totalSession = 0;
		for(int i=0; i

以上就是Java实战之电影在线观看系统的实现的详细内容,更多关于Java电影观看系统的资料请关注编程笔记其它相关文章!


推荐阅读
author-avatar
捕风的水中龙_106
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有