0


Java项目:电影在线观看系统(java+ssm+jsp+layui+maven+mysql)

源码获取:博客首页 "资源" 里下载!

一、项目简述

环境配置:

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<User> 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<Boolean> 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<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);
        }
        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<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){
            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<Boolean> 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<MovieComment> 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<Boolean> 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<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);
        }
        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 ssm maven

本文转载自: https://blog.csdn.net/yuyecsdn/article/details/124098568
版权归原作者 pastclouds 所有, 如有侵权,请联系我们删除。

“Java项目:电影在线观看系统(java+ssm+jsp+layui+maven+mysql)”的评论:

还没有评论