基于javaweb+mysql的ssm+maven电影院购票选座管理系统(java+ssm+mysql+jsp)
私信源码获取及调试交流
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb的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
/**
*/
@Service
@Transactional
public class OrderServiceImpl implements IOrderService {
@Resource
private OrderMapper orderMapper;
@Resource
private SessionMapper sessionMapper;
@Resource
private CinemaMapper cinemaMapper;
@Resource
private MovieMapper movieMapper;
@Resource
private OrderItemMapper orderItemMapper;
@Resource
private UserMapper userMapper;
@Resource
private ISessionService sessionService;
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;
/**
* 封装分页数据
* @param page
* @param name
* @return
*/
@Override
public ResponseVo<Page> getPage(Page page, String name) {
UserExample userExample = new UserExample();
userExample.createCriteria().andUsernameLike('%'+name+'%');
page.setTotalCount(userMapper.countByExample(userExample));
return ResponseVo.success(page);
}
/**
* 获取用户列表数据
* @param name
* @param page
* @return
*/
@Override
public ResponseVo<List<User>> list(String name, Page page) {
UserExample userExample = new UserExample();
if(!CommonUtil.isEmpty(name)){
// 进行了搜索
userExample.createCriteria().andUsernameLike('%' + name + '%');
}
PageHelper.startPage(page.getPage(), page.getRows());
* 电影列表页面
* @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 name
* @param page
* @return
*/
@RequestMapping(value="/list",method = RequestMethod.POST)
@ResponseBody
public List<Movie> list(String name, Page page){
return movieService.list(name, page).getData();
}
/**
* 封装分页数据
* @return
*/
@RequestMapping(value="/page",method = RequestMethod.POST)
@ResponseBody
public Page page(Page page, String name){
return movieService.getPage(page, name).getData();
}
/**
* 保存电影信息
* @param movie
* @return
*/
@RequestMapping(value="/save",method = RequestMethod.POST)
@ResponseBody
public ResponseVo<Boolean> save(Movie movie){
return movieService.save(movie);
}
/**
* 删除电影信息
* @param id
*/
@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;
/**
* 角色列表页面
* @param model
* @return
*/
@RequestMapping(value="/index",method = RequestMethod.GET)
public ModelAndView index(ModelAndView model){
model.addObject("firstMenu", "role");
model.addObject("secondMenu", "role-index");
model.addObject("Page", roleService.getPage(new Page(), "").getData());
model.setViewName("admin/role/index");
return model;
}
/**
* 角色列表数据获取
/**
*/
@Controller("AdminCinemaController")
@RequestMapping("/admin/cinema")
public class CinemaController {
@Resource
private ICinemaService cinemaService;
/**
* 电影院列表页面
* @param model
* @return
*/
@RequestMapping(value="/index",method = RequestMethod.GET)
public ModelAndView index(ModelAndView model){
model.addObject("firstMenu", "cinema");
model.addObject("secondMenu", "cinema-index");
model.addObject("Page", cinemaService.getPage(new Page(), "").getData());
model.setViewName("admin/cinema/index");
return model;
}
/**
* 电影院列表数据获取
* @param name
* @param page
* @return
*/
@RequestMapping(value="/list",method = RequestMethod.POST)
@ResponseBody
public List<Cinema> list(String name, Page page){
return cinemaService.list(name, page).getData();
}
/**
* 封装分页数据
* @return
*/
@RequestMapping(value="/page",method = RequestMethod.POST)
@ResponseBody
public Page page(Page page, String name){
return cinemaService.getPage(page, name).getData();
}
/**
* 保存电影院信息
* @param cinema
* @return
String generatorVCode = captchaUtil.generatorVCode(); //验证码的值
//将生成的验证码放入session,以供放后面程序的验证使用
request.getSession().setAttribute(method, generatorVCode);
log.info("验证码成功生成,method=" + method + ",value=" + generatorVCode);
try {
ImageIO.write(captchaUtil.generatorRotateVCodeImage(generatorVCode, true), "gif", response.getOutputStream());
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
*/
@Controller("AdminCinemaController")
@RequestMapping("/admin/cinema")
public class CinemaController {
@Resource
private ICinemaService cinemaService;
/**
* 电影院列表页面
* @param model
* @return
*/
@RequestMapping(value="/index",method = RequestMethod.GET)
public ModelAndView index(ModelAndView model){
model.addObject("firstMenu", "cinema");
model.addObject("secondMenu", "cinema-index");
model.addObject("Page", cinemaService.getPage(new Page(), "").getData());
model.setViewName("admin/cinema/index");
return model;
}
/**
* 电影院列表数据获取
* @param name
/**
* 根据订单id获取订单详情的
* @param id
* @return
*/
@Override
public List<OrderItem> getOrderItemList(String id) {
if(CommonUtil.isEmpty(id)){
return new ArrayList<>();
}
OrderItemExample orderItemExample = new OrderItemExample();
orderItemExample.createCriteria().andOrderIdEqualTo(id);
return orderItemMapper.selectByExample(orderItemExample);
}
/**
* 保存订单信息
* @param order
* @return
*/
@Override
public ResponseVo<Boolean> save(Order order) {
if(order == null){
return ResponseVo.errorByMsg(CodeMsg.DATA_ERROR);
}
// 保存订单信息操作
if(orderMapper.updateByPrimaryKeySelective(order) == 0){
return ResponseVo.errorByMsg(CodeMsg.ORDER_SAVE_ERROR);
}
return ResponseVo.success(true);
}
/**
* 删除订单信息
* @param id
* @return
*/
@Override
public ResponseVo<Boolean> delete(String id) {
if(CommonUtil.isEmpty(id)){
return ResponseVo.errorByMsg(CodeMsg.DATA_ERROR);
}
// 删除订单详情数据
OrderItemExample orderItemExample = new OrderItemExample();
orderItemExample.createCriteria().andOrderIdEqualTo(id);
if(orderItemMapper.deleteByExample(orderItemExample) == 0){
throw new RuntimeException("订单信息删除失败,请联系管理员!");
}
// 删除订单数据
if(orderMapper.deleteByPrimaryKey(id) == 0){
throw new RuntimeException("订单信息删除失败,请联系管理员!");
private IOrderService orderService;
@Resource
private ICinemaService cinemaService;
@Resource
private ICommentService commentService;
/**
* 系统首页页面
* @param model
* @return
*/
@RequestMapping(value="/index",method = RequestMethod.GET)
public ModelAndView index(ModelAndView model){
model.addObject("firstMenu", "system");
model.addObject("roleList", roleService.all().getData());
model.addObject("userTotal", userService.getTotal().getData());
model.addObject("cinemaTotal", cinemaService.getTotal().getData());
model.addObject("movieTotal", movieService.getTotal().getData());
model.addObject("commentTotal", commentService.getTotal().getData());
model.addObject("orderTotal", orderService.getTotal().getData());
model.addObject("sessionTotal", sessionService.getTotal().getData());
model.setViewName("admin/system/index");
return model;
}
}
/**
*/
/**
* 运行时触发异常捕获
*/
@ControllerAdvice
public class ExceptionsHandler {
private final Logger logger = LoggerFactory.getLogger(ExceptionsHandler.class);
model.addObject("Page", sessionService.getPage(new Page(), "").getData());
model.addObject("cinemaList", cinemaService.list("", new Page(1, cinemaService.getTotal().getData())).getData());
model.addObject("movieList", movieService.list("", new Page(1, movieService.getTotal().getData())).getData());
model.setViewName("admin/session/index");
return model;
}
/**
* 场次列表数据获取
* @param name
* @param page
* @return
*/
@RequestMapping(value="/list",method = RequestMethod.POST)
@ResponseBody
public List<Session> list(String name, Page page){
return sessionService.list(name, page).getData();
}
/**
* 封装分页数据
* @return
*/
@RequestMapping(value="/page",method = RequestMethod.POST)
@ResponseBody
public Page page(Page page, String name){
return sessionService.getPage(page, name).getData();
}
/**
* 保存场次信息
* @param session
* @return
*/
@RequestMapping(value="/save",method = RequestMethod.POST)
@ResponseBody
public ResponseVo<Boolean> save(Session session){
return sessionService.save(session);
}
/**
* 删除场次信息
* @param id
* @return
*/
@RequestMapping(value="/delete",method = RequestMethod.POST)
@ResponseBody
/**
*/
@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;
/**
* 封装分页数据
* @param page
* @param name
* @return
*/
@Override
public ResponseVo<Page> getPage(Page page, String name) {
UserExample userExample = new UserExample();
userExample.createCriteria().andUsernameLike('%'+name+'%');
page.setTotalCount(userMapper.countByExample(userExample));
return ResponseVo.success(page);
}
loginUser.setLoginTime(new Date());
userMapper.updateByPrimaryKeySelective(loginUser);
request.getSession().setAttribute(RuntimeConstant.HOME_USER, loginUser);
return ResponseVo.successByMsg(true, "登录成功!");
}
/**
* 后台用户登录
* @param user
* @param request
* @return
*/
@Override
public ResponseVo<Boolean> adminLogin(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("admin_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())
.andRoleIdEqualTo(RoleEnum.ADMIN.getCode());
List<User> userList = userMapper.selectByExample(userExample);
if(userList == null || userList.size() != 1){
return ResponseVo.errorByMsg(CodeMsg.USERNAME_PASSWORD_ERROR);
}
/**
* 角色列表数据获取
* @param name
* @param page
* @return
*/
@RequestMapping(value="/list",method = RequestMethod.POST)
@ResponseBody
public List<Role> list(String name, Page page){
return roleService.list(name, page).getData();
}
/**
* 封装分页数据
* @return
*/
@RequestMapping(value="/page",method = RequestMethod.POST)
@ResponseBody
public Page page(Page page, String name){
return roleService.getPage(page, name).getData();
}
/**
* 保存角色信息
* @param role
* @return
*/
@RequestMapping(value="/save",method = RequestMethod.POST)
@ResponseBody
public ResponseVo<Boolean> save(Role role){
return roleService.save(role);
}
/**
* 删除角色信息
* @param id
* @return
*/
@RequestMapping(value="/delete",method = RequestMethod.POST)
@ResponseBody
public ResponseVo<Boolean> delete(String id){
return roleService.delete(id);
}
}
//若不存在改目录,则创建目录
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, "图片上传成功!");
}
/**
* 系统统一的图片查看方法
* @param filename
* @return
*/
@RequestMapping(value="/view_photo")
@ResponseBody
public ResponseEntity<?> viewPhoto(@RequestParam(name="filename",required=true)String filename){
String uploadPhotoPath = RuntimeConstant.BASE_UPLOAD_PHOTO_PATH;
String fileDate = CommonUtil.getFileDate(filename); //取得文件路径中的日期部分
logger.info("文件路径中日期部分:{}",fileDate);
filename = "\\" + filename.substring(filename.lastIndexOf("/") + 1); //取得文件名
Resource resource = resourceLoader.getResource("file:" + uploadPhotoPath + fileDate + filename);
logger.info("查看图片路径:{}",uploadPhotoPath + fileDate + filename);
try {
return ResponseEntity.ok(resource);
} catch (Exception e) {
return ResponseEntity.notFound().build();
}
}
}
* 用户修改个人信息操作处理
* @param user
* @return
*/
@Override
public ResponseVo<Boolean> saveUserInfo(User user, HttpServletRequest request) {
if(user == null){
return ResponseVo.errorByMsg(CodeMsg.DATA_ERROR);
}
if(userMapper.updateByPrimaryKeySelective(user) == 0){
return ResponseVo.errorByMsg(CodeMsg.SAVE_USER_INFO_ERROR);
}
User newUser = userMapper.selectByPrimaryKey(user.getId());
request.getSession().setAttribute(RuntimeConstant.HOME_USER, newUser);
return ResponseVo.successByMsg(true, "保存用户个人信息成功!");
}
/**
* 判断用户昵称是否重复
* @param user
* @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;//没有重名
}
}
/**
*/
@Controller("HomeOrderController")
@RequestMapping("/home/order")
public class OrderController {
@Resource
private IOrderService orderService;
/**
* 订单支付页面
* @param model
* @param orderId
* @return
*/
@RequestMapping(value="/pay",method = RequestMethod.GET)
public ModelAndView pay(ModelAndView model, String orderId){
model.addObject("order", orderService.getById(orderId).getData());
model.setViewName("home/order/pay");
return model;
}
/**
* 支付订单操作处理
* @param id
* @return
*/
@RequestMapping(value="/pay",method = RequestMethod.POST)
@ResponseBody
public ResponseVo<Boolean> pay(String id){
/**
* 角色列表数据获取
* @param name
* @param page
* @return
*/
@RequestMapping(value="/list",method = RequestMethod.POST)
@ResponseBody
public List<Role> list(String name, Page page){
return roleService.list(name, page).getData();
}
/**
* 封装分页数据
* @return
*/
@RequestMapping(value="/page",method = RequestMethod.POST)
@ResponseBody
public Page page(Page page, String name){
return roleService.getPage(page, name).getData();
}
/**
* 保存角色信息
* @param role
* @return
*/
@RequestMapping(value="/save",method = RequestMethod.POST)
@ResponseBody
public ResponseVo<Boolean> save(Role role){
return roleService.save(role);
}
/**
* 删除角色信息
* @param id
* @return
*/
@RequestMapping(value="/delete",method = RequestMethod.POST)
@ResponseBody
* 封装分页数据
* @return
*/
@RequestMapping(value="/page",method = RequestMethod.POST)
@ResponseBody
public Page page(Page page, String name){
return userService.getPage(page, name).getData();
}
/**
* 保存用户信息
* @param user
* @return
*/
@RequestMapping(value="/save",method = RequestMethod.POST)
@ResponseBody
public ResponseVo<Boolean> save(User user){
return userService.save(user);
}
/**
* 删除用户信息
* @param id
* @return
*/
@RequestMapping(value="/delete",method = RequestMethod.POST)
@ResponseBody
public ResponseVo<Boolean> delete(String id){
return userService.delete(id);
}
/**
* 用户登录操作处理
* @param user
* @param request
* @return
*/
@RequestMapping(value="/login",method = RequestMethod.POST)
@ResponseBody
public ResponseVo<Boolean> login(User user, HttpServletRequest request){
return userService.adminLogin(user, request);
}
/**
* 退出登录操作处理
* @param request
* @return
*/
@RequestMapping(value="/logout",method = RequestMethod.POST)
@ResponseBody