基于javaweb+mysql的ssm+maven电影院购票选座管理系统(java+ssm+mysql+jsp)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SSM+Maven电影院购票选座管理系统(java+ssm+mysql+jsp)
启动前先修改图片的上传路径:
com.demo.constant.RuntimeConstant#BASE_UPLOAD_PHOTO_PATH
后台:
http://localhost:8080/admin/user/login
admin 123456
前台:
http://localhost:8080/home/user/login
user1 123456
user2 123456
项目描述:这是一个基于SSM框架开发的电影院选座购票系统。首先,这个项目页面简洁清爽,易于理解和学习。其次,这项目功能丰富,具有一个电影院选座购票系统该有的所有功能。
项目功能:此项目分为两个角色:普通用户和管理员。普通用户有登录注册、浏览和筛选电影信息、评论、评分电影信息、选座购票、查看个人信息、查看个人订单信息等等功能。管理员有登录、管理所有用户信息、管理所有电影信息、管理所有评论信息、管理所有订单信息、管理所有角色信息、管理所有电影院信息、管理所有场次信息等等功能。
应用技术:Jsp + SSM + MySQL + LayUI + Bootstrap
运行环境:Eclipse/IntelliJ IDEA + MySQL5.7(项目压缩包中自带) + Tomcat8.5(项目压缩包中自带) + JDK1.8 + Maven3.6.3
public class FileController {
private Logger logger = LoggerFactory.getLogger(FileController.class);
@Autowired
private ResourceLoader resourceLoader;
/**
* 上传图片统一处理
* @param photo
* @param request
* @return
*/
@RequestMapping(value="/upload_photo",method= RequestMethod.POST)
@ResponseBody
public ResponseVo<String> uploadPhoto(MultipartFile photo, HttpServletRequest request){
if(photo == null){
return ResponseVo.errorByMsg(CodeMsg.PHOTO_EMPTY);
}
//检查上传文件大小 不能超过1MB
if(photo.getSize() > 1 * 1024* 1024) {
return ResponseVo.errorByMsg(CodeMsg.PHOTO_SURPASS_MAX_SIZE);
}
//获取文件后缀
String suffix = photo.getOriginalFilename().substring(photo.getOriginalFilename().lastIndexOf(".")+1,photo.getOriginalFilename().length());
if(!CommonUtil.isPhoto(suffix)){
return ResponseVo.errorByMsg(CodeMsg.PHOTO_FORMAT_NOT_CORRECT);
}
String path = request.getContextPath();
String savePath = RuntimeConstant.BASE_UPLOAD_PHOTO_PATH + CommonUtil.getFormatterDate(new Date(), "yyyyMMdd") + "\\";
File savePathFile = new File(savePath);
if(!savePathFile.exists()){
//若不存在改目录,则创建目录
savePathFile.mkdir();
}
String filename = new Date().getTime()+"."+suffix;
logger.info("保存图片的路径:{}",savePath + filename);
try {
//将文件保存至指定目录
photo.transferTo(new File(savePath + filename));
}catch (Exception e) {
e.printStackTrace();
return ResponseVo.errorByMsg(CodeMsg.SAVE_FILE_EXCEPTION);
}
String filepath = "../resources/upload/" + CommonUtil.getFormatterDate(new Date(), "yyyyMMdd") + "/" + filename;
return ResponseVo.successByMsg(filepath, "图片上传成功!");
}
/**
* 系统统一的图片查看方法
return movieService.save(movie);
}
/**
* 删除电影信息
* @param id
* @return
*/
@RequestMapping(value="/delete",method = RequestMethod.POST)
@ResponseBody
public ResponseVo<Boolean> delete(String id){
return movieService.delete(id);
}
}
/**
*/
@Controller("AdminRoleController")
@RequestMapping("/admin/role")
public class RoleController {
@Resource
private IRoleService roleService;
*/
@RequestMapping(value="/delete",method = RequestMethod.POST)
@ResponseBody
public ResponseVo<Boolean> delete(String id){
return sessionService.delete(id);
}
}
/**
*/
@Controller("AdminOrderController")
@RequestMapping("/admin/order")
public class OrderController {
@Resource
private IOrderService orderService;
/**
* 订单列表页面
* @param model
* @param name
* @return
*/
@RequestMapping(value="/index",method = RequestMethod.GET)
public ModelAndView index(ModelAndView model, String name){
model.addObject("firstMenu", "order");
model.addObject("secondMenu", "order-index");
model.addObject("Page", orderService.getPage(new Page(), name).getData());
model.setViewName("admin/order/index");
return model;
}
/**
* 订单列表数据获取
* @param name
* @param page
* @return
*/
@Resource
private UserMapper userMapper;
@Resource
private ISessionService sessionService;
/**
* 生成订单操作处理
* @param orderItemList
* @param order
* @param request
* @return
*/
@Override
public ResponseVo<Order> generateOrder(List<OrderItem> orderItemList, Order order, HttpServletRequest request) {
if(order == null || orderItemList == null || orderItemList.size() == 0) {
return ResponseVo.errorByMsg(CodeMsg.DATA_ERROR);
}
if(CommonUtil.isEmpty(order.getSessionId()) || CommonUtil.isEmpty(order.getCinemaId()) || CommonUtil.isEmpty(order.getMovieId())){
return ResponseVo.errorByMsg(CodeMsg.DATA_ERROR);
}
Cinema cinema = cinemaMapper.selectByPrimaryKey(order.getCinemaId());
Session session = sessionMapper.selectByPrimaryKey(order.getSessionId());
Movie movie = movieMapper.selectByPrimaryKey(order.getMovieId());
if(cinema == null || session == null | movie == null){
return ResponseVo.errorByMsg(CodeMsg.DATA_ERROR);
}
// 判断场次时间是否已经超过
if(session.getTime().getTime() < (new Date()).getTime()){
return ResponseVo.errorByMsg(CodeMsg.SESSION_TIME_OVER);
}
// 判断座位数是否足够
if(session.getTotalSeat() - session.getOrderSeat() < orderItemList.size()){
return ResponseVo.errorByMsg(CodeMsg.ORDER_SEAT_ERROR);
}
BigDecimal totalPrice = new BigDecimal("0.00");
String orderId = UuidUtil.getShortUuid();
order.setTradeNo(String.valueOf(new SnowFlake(2,3).nextId()));
order.setId(orderId);
order.setState(OrderStateEnum.NO_PAY.getCode());
User user = (User) request.getSession().getAttribute(RuntimeConstant.HOME_USER);
order.setUserId(user.getId());
order.setCinemaName(cinema.getName());
public ResponseVo<Boolean> delete(String id){
return cinemaService.delete(id);
}
}
/**
*/
@Controller("AdminMovieController")
@RequestMapping("/admin/movie")
public class MovieController {
@Resource
private IMovieService movieService;
/**
* 电影列表页面
* @param model
* @return
*/
@RequestMapping(value="/index",method = RequestMethod.GET)
public ModelAndView index(ModelAndView model){
model.addObject("firstMenu", "movie");
model.addObject("secondMenu", "movie-index");
model.addObject("Page", movieService.getPage(new Page(), "").getData());
model.setViewName("admin/movie/index");
return model;
}
/**
* @param id
* @return
*/
@RequestMapping(value="/delete",method = RequestMethod.POST)
@ResponseBody
public ResponseVo<Boolean> delete(String id){
return orderService.delete(id);
}
}
/**
*/
/**
* 验证码生成控制器
*/
@Controller("CaptchaController")
@RequestMapping("/common/captcha")
public class CaptchaController {
private Logger log = LoggerFactory.getLogger(CaptchaController.class);
/**
* 通用验证码生成器
* @param vcodeLength
* @param fontSize
* @param width
* @param height
* @param method
* @param request
* @param response
*/
@RequestMapping(value="/generate_captcha",method = RequestMethod.GET)
public void generateCaptcha(
@RequestParam(name="vl",defaultValue="4")Integer vcodeLength,//vcodeLength,验证码长度
* @param id
* @return
*/
public Boolean isUsernameExist(User user, String id) {
UserExample userExample = new UserExample();
userExample.createCriteria().andUsernameEqualTo(user.getUsername());
List<User> selectedUserList = userMapper.selectByExample(userExample);
if(selectedUserList != null && selectedUserList.size() > 0) {
if(selectedUserList.size() > 1){
return true; //出现重名
}
if(!selectedUserList.get(0).getId().equals(id)) {
return true; //出现重名
}
}
return false;//没有重名
}
}
/**
* 用户注册操作处理
* @param user
* @param request
* @return
*/
@RequestMapping(value="/register",method = RequestMethod.POST)
@ResponseBody
public ResponseVo<Boolean> register(User user, HttpServletRequest request){
return userService.register(user, request);
}
/**
* 用户个人中心页面
* @param model
* @return
*/
@RequestMapping(value="/center",method = RequestMethod.GET)
public ModelAndView center(ModelAndView model, HttpServletRequest request){
User user = (User) request.getSession().getAttribute(RuntimeConstant.HOME_USER);
model.addObject("orderList", orderService.getByUserId(user.getId()).getData());
model.setViewName("home/user/center");
return model;
}
/**
* 退出登录操作处理
* @param request
* @return
*/
@RequestMapping(value="/logout",method = RequestMethod.POST)
@ResponseBody
public ResponseVo<Boolean> logout(HttpServletRequest request){
request.getSession().setAttribute(RuntimeConstant.HOME_USER, null);
return ResponseVo.successByMsg(true, "退出登录成功!");
}
/**
* 用户修改个人信息操作处理
* @param user
* @param request
/**
*/
@Controller("HomeUserController")
@RequestMapping("/home/user")
public class UserController {
@Resource
private IUserService userService;
@Resource
private IOrderService orderService;
/**
* 用户登录/注册页面
* @param model
* @return
*/
@RequestMapping(value="/login",method = RequestMethod.GET)
public ModelAndView login(ModelAndView model){
model.setViewName("home/user/login");
return model;
}
/**
* 用户登录操作处理
* @param user
* @param request
* @return
*/
@RequestMapping(value="/login",method = RequestMethod.POST)
@ResponseBody
public ResponseVo<Boolean> login(User user, HttpServletRequest request){
return userService.homeLogin(user, request);
}
/**
* 用户注册操作处理
* @param user
* @param request
* @return
*/
/**
*/
@Service
@Transactional
public class UserServiceImpl implements IUserService {
@Resource
private UserMapper userMapper;
@Resource
private RoleMapper roleMapper;
@Resource
private CommentMapper commentMapper;
@Resource
private IOrderService orderService;
@Resource
private OrderMapper orderMapper;
@Resource
private IRateService rateService;
@Resource
private RateMapper rateMapper;
if(orderItemMapper.deleteByExample(orderItemExample) == 0){
throw new RuntimeException("订单信息删除失败,请联系管理员!");
}
// 删除订单数据
if(orderMapper.deleteByPrimaryKey(id) == 0){
throw new RuntimeException("订单信息删除失败,请联系管理员!");
}
// 重新计算已定座位数
sessionService.sumOrderSeat();
return ResponseVo.success(true);
}
/**
* 获取订单的总数
* @return
*/
@Override
public ResponseVo<Integer> getTotal() {
return ResponseVo.success(orderMapper.countByExample(new OrderExample()));
}
}
/**
return ResponseVo.errorByMsg(validate);
}
if(CommonUtil.isEmpty(user.getId())){
// 添加操作
// 判断用户昵称是否存在
if(isUsernameExist(user, "")){
return ResponseVo.errorByMsg(CodeMsg.USERNAME_EXIST);
}
user.setId(UuidUtil.getShortUuid());
user.setLoginTime(new Date());
if(userMapper.insertSelective(user) == 0){
return ResponseVo.errorByMsg(CodeMsg.USER_ADD_ERROR);
}
}else {
// 修改操作
// 判断用户昵称是否存在
if(isUsernameExist(user, user.getId())){
return ResponseVo.errorByMsg(CodeMsg.USERNAME_EXIST);
}
if(userMapper.updateByPrimaryKeySelective(user) == 0){
return ResponseVo.errorByMsg(CodeMsg.USER_EDIT_ERROR);
}
}
return ResponseVo.success(true);
}
/**
* 获取用户的总数
* @return
*/
@Override
public ResponseVo<Integer> getTotal() {
return ResponseVo.success(userMapper.countByExample(new UserExample()));
}
/**
* 删除用户信息
* @param id
* @return
*/
@Override
public ResponseVo<Boolean> delete(String id) {
if(CommonUtil.isEmpty(id)){
return ResponseVo.errorByMsg(CodeMsg.DATA_ERROR);
}
// 删除评论信息
CommentExample commentExample = new CommentExample();
commentExample.createCriteria().andUserIdEqualTo(id);
* 前台用户登录操作处理
* @param user
* @param request
* @return
*/
@Override
public ResponseVo<Boolean> homeLogin(User user, HttpServletRequest request) {
if(user == null){
return ResponseVo.errorByMsg(CodeMsg.DATA_ERROR);
}
if(CommonUtil.isEmpty(user.getUsername())){
return ResponseVo.errorByMsg(CodeMsg.USERNAME_EMPTY);
}
if(CommonUtil.isEmpty(user.getPassword())){
return ResponseVo.errorByMsg(CodeMsg.PASSWORD_EMPTY);
}
// 验证验证码输入是否正确
String correctCaptcha = (String) request.getSession().getAttribute("home_login");
if(CommonUtil.isEmpty(correctCaptcha)){
return ResponseVo.errorByMsg(CodeMsg.CAPTCHA_EXPIRED);
}
if(!(correctCaptcha.toLowerCase()).equals(user.getCaptcha().toLowerCase())){
return ResponseVo.errorByMsg(CodeMsg.CAPTCHA_ERROR);
}
// 验证用户昵称和密码是否正确
UserExample userExample = new UserExample();
userExample.createCriteria().andUsernameEqualTo(user.getUsername()).andPasswordEqualTo(user.getPassword());
List<User> userList = userMapper.selectByExample(userExample);
if(userList == null || userList.size() != 1){
return ResponseVo.errorByMsg(CodeMsg.USERNAME_PASSWORD_ERROR);
}
User loginUser = userList.get(0);
loginUser.setLoginTime(new Date());
userMapper.updateByPrimaryKeySelective(loginUser);
request.getSession().setAttribute(RuntimeConstant.HOME_USER, loginUser);
return ResponseVo.successByMsg(true, "登录成功!");
}
/**
* 后台用户登录
* @param user
* @param request
* @return
}
// 增加已预订座位数
session.setOrderSeat(session.getOrderSeat() + orderItemList.size());
if(sessionMapper.updateByPrimaryKeySelective(session) == 0){
throw new RuntimeException("生成订单失败,请稍后重试!");
}
return ResponseVo.successByMsg(order ,"确认选座成功!");
}
/**
* 根据用户id获取订单数据
* @param userId
* @return
*/
@Override
public ResponseVo<List<Order>> getByUserId(String userId) {
if(CommonUtil.isEmpty(userId)){
return ResponseVo.errorByMsg(CodeMsg.DATA_ERROR);
}
OrderExample orderExample = new OrderExample();
orderExample.createCriteria().andUserIdEqualTo(userId);
orderExample.setOrderByClause("create_time desc");
List<Order> orderList = orderMapper.selectByExample(orderExample);
OrderItemExample orderItemExample = new OrderItemExample();
for(Order order : orderList){
orderItemExample.createCriteria().andOrderIdEqualTo(order.getId());
List<OrderItem> orderItemList = orderItemMapper.selectByExample(orderItemExample);
order.setOrderItemList(orderItemList);
}
return ResponseVo.success(orderList);
}
/**
* 根据订单id获取订单信息
* @param id
* @return
*/
@Override
public ResponseVo<Order> getById(String id) {
if(CommonUtil.isEmpty(id)){
return ResponseVo.errorByMsg(CodeMsg.DATA_ERROR);
}
Order order = orderMapper.selectByPrimaryKey(id);
OrderItemExample orderItemExample = new OrderItemExample();
orderItemExample.createCriteria().andOrderIdEqualTo(id);
List<OrderItem> orderItemList = orderItemMapper.selectByExample(orderItemExample);
order.setOrderItemList(orderItemList);
return ResponseVo.success(order);
}
/**
* 支付订单操作处理
order.setMoviePhoto(movie.getPhoto());
order.setSessionHall(session.getHall());
order.setSessionTime(session.getTime());
order.setCreateTime(new Date());
totalPrice = session.getPrice().multiply(new BigDecimal(orderItemList.size()));
order.setTotalPrice(totalPrice);
for(OrderItem orderItem : orderItemList){
orderItem.setOrderId(orderId);
orderItem.setPrice(session.getPrice());
orderItem.setId(UuidUtil.getShortUuid());
orderItem.setSessionId(session.getId());
if(orderItemMapper.insertSelective(orderItem) == 0){
throw new RuntimeException("生成订单失败,请稍后重试!");
}
}
if(orderMapper.insertSelective(order) == 0){
throw new RuntimeException("生成订单失败,请稍后重试!");
}
// 增加已预订座位数
session.setOrderSeat(session.getOrderSeat() + orderItemList.size());
if(sessionMapper.updateByPrimaryKeySelective(session) == 0){
throw new RuntimeException("生成订单失败,请稍后重试!");
}
return ResponseVo.successByMsg(order ,"确认选座成功!");
}
/**
* 根据用户id获取订单数据
* @param userId
* @return
*/
@Override
public ResponseVo<List<Order>> getByUserId(String userId) {
if(CommonUtil.isEmpty(userId)){
return ResponseVo.errorByMsg(CodeMsg.DATA_ERROR);
}
OrderExample orderExample = new OrderExample();
orderExample.createCriteria().andUserIdEqualTo(userId);
orderExample.setOrderByClause("create_time desc");
List<Order> orderList = orderMapper.selectByExample(orderExample);
OrderItemExample orderItemExample = new OrderItemExample();
for(Order order : orderList){
orderItemExample.createCriteria().andOrderIdEqualTo(order.getId());
List<OrderItem> orderItemList = orderItemMapper.selectByExample(orderItemExample);
order.setOrderItemList(orderItemList);
}
return ResponseVo.success(orderList);
}
/**
* 用户登录操作处理
* @param user
* @param request
* @return
*/
@RequestMapping(value="/login",method = RequestMethod.POST)
@ResponseBody
public ResponseVo<Boolean> login(User user, HttpServletRequest request){
return userService.homeLogin(user, request);
}
/**
* 用户注册操作处理
* @param user
* @param request
* @return
*/
@RequestMapping(value="/register",method = RequestMethod.POST)
@ResponseBody
public ResponseVo<Boolean> register(User user, HttpServletRequest request){
return userService.register(user, request);
}
/**
* 用户个人中心页面
* @param model
* @return
*/
@RequestMapping(value="/center",method = RequestMethod.GET)
public ModelAndView center(ModelAndView model, HttpServletRequest request){
User user = (User) request.getSession().getAttribute(RuntimeConstant.HOME_USER);
model.addObject("orderList", orderService.getByUserId(user.getId()).getData());
model.setViewName("home/user/center");
return model;
}
/**
* 退出登录操作处理
* @param request
* @return
*/
@RequestMapping(value="/logout",method = RequestMethod.POST)
@ResponseBody
public ResponseVo<Boolean> logout(HttpServletRequest request){
request.getSession().setAttribute(RuntimeConstant.HOME_USER, null);
return ResponseVo.successByMsg(true, "退出登录成功!");
}
/**
/**
*/
@Controller("FileController")
@RequestMapping("/common/file")
public class FileController {
private Logger logger = LoggerFactory.getLogger(FileController.class);
@Autowired
private ResourceLoader resourceLoader;
/**
* 上传图片统一处理
* @param photo
* @param request
* @return
*/
@RequestMapping(value="/upload_photo",method= RequestMethod.POST)
@ResponseBody
public ResponseVo<String> uploadPhoto(MultipartFile photo, HttpServletRequest request){
if(photo == null){
return ResponseVo.errorByMsg(CodeMsg.PHOTO_EMPTY);
}
//检查上传文件大小 不能超过1MB
if(photo.getSize() > 1 * 1024* 1024) {
return ResponseVo.errorByMsg(CodeMsg.PHOTO_SURPASS_MAX_SIZE);
}
//获取文件后缀
String suffix = photo.getOriginalFilename().substring(photo.getOriginalFilename().lastIndexOf(".")+1,photo.getOriginalFilename().length());
if(!CommonUtil.isPhoto(suffix)){
return ResponseVo.errorByMsg(CodeMsg.PHOTO_FORMAT_NOT_CORRECT);
}
String path = request.getContextPath();
String savePath = RuntimeConstant.BASE_UPLOAD_PHOTO_PATH + CommonUtil.getFormatterDate(new Date(), "yyyyMMdd") + "\\";
File savePathFile = new File(savePath);
if(!savePathFile.exists()){
//若不存在改目录,则创建目录
savePathFile.mkdir();