Java实战之电影在线观看系统的实现(java实现电影网站)

网友投稿 639 2022-08-04


Java实战之电影在线观看系统的实现(java实现电影网站)

目录一、项目简述二、效果图展示三、核心代码后台用户管理控制器电影管理控制器前台电影控制器

一、项目简述

环境配置:

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(Mohttp://del 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(ETiKl)){

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 OrETiKlderService 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";

}

/**

* 统计电影上映场次

* @ETiKlparam 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< showTotal.size();i++){

totalSession += Integer.parseInt(showTotal.get(i)+"");

}

ret.add(totalSession);

return Result.success(ret);

}

}

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


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Java负载均衡算法实现之轮询和加权轮询(负载均衡原理)
下一篇:SpringCloud 分布式锁的多种实现
相关文章

 发表评论

暂时没有评论,来抢沙发吧~