一、项目简述
环境配置:
Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)
项目技术:
JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax + layui+ maven等等。
二、效果图展示
三、核心代码
后台用户管理控制器
@RequestMapping("/admin/user")
@Controller
public class UserController {
@Autowired
private UserService userService;
@Autowired
private RoleService roleService;
@Autowired
private OperaterLogService operaterLogService;
@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";
}
@RequestMapping(value="/add",method=RequestMethod.GET)
public String add(Model model){
model.addAttribute("roles", roleService.findAll());
return "admin/user/add";
}
@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);
}
@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";
}
@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);
}
@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);
}
}
电影管理控制器
@RequestMapping("/admin/movie")
@Controller
public class MovieController {
@Autowired
private MovieService movieService;
@Autowired
private MovieCommentService movieCommentService;
@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";
}
@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";
}
@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";
}
@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);
}
@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);
}
@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";
}
@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);
}
}
前台电影控制器
@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;
@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";
}
@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";
}
@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";
}
@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";
}
@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实战之电影在线观看系统的实现的详细内容,更多关于Java电影观看系统的资料请关注编程网其它相关文章!