源码获取:博客首页 "资源" 里下载!
项目介绍
本项目代码架构设计简单,注释齐全,结构清晰,适合同为java初学者参考。
项目是一套电影院会员管理系统,使用前后端分离架构开发,前端基于Vue.js+Element UI技术,后端使用springboot+mybatis实现,包含管理员、会员管理、会员卡管理、电影票、消费记录、数据统计等模块
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.是否Maven项目: 是;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目
6.数据库:MySql 5.7版本;
技术栈
后端:springboot+mybatis
前端:vue.js+element-ui
使用说明
数据库文件cinema.sql已整合到项目中,使用mysql导入即可生成数据库
本项目已经整合了前后端,前端文件经过webpack构建后,生成了static文件夹和index.html放入了webapp下。
要对前端页面进行修改,修改完成后同样将生成的文件放到本项目的webapp下。
程序设计文档可参考目录下:电影院会员管理系统说明文档.docx
运行项目
- 方法一: cinema项目中已经整合了vue打包的静态资源,直接启动项目,并在浏览器上输入http://localhost:8081/cinema 即可运行。
- 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,下载所需jar包;
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
- 将项目中db.properties配置文件中的数据库配置改为自己的配置
- 配置tomcat,然后运行项目,输入http://localhost:8081/cinema 登录
- 账户:admin 密码:123123
- 方法二: cinema-web项目是cinema项目的vue单页面前端项目,可以在文件夹目录下命令行输入:
npm run install
npm run dev
后,修改utils/request.js下baseURL=”/api”,开启node反向代理服务器,解决跨域问题,然后启动cinema后端项目,在浏览器上输入 http://localhost:8080 即可以前后端分离方式运行(也可以npm run build后将dist文件夹放到nginx下运行)
后台用户管理控制器:
/**
* 后台用户管理控制器
* @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/role")
@Controller
public class RoleController {
private Logger log = LoggerFactory.getLogger(RoleController.class);
@Autowired
private MenuService menuService;
@Autowired
private OperaterLogService operaterLogService;
@Autowired
private RoleService roleService;
/**
* 分页搜索角色列表
* @param model
* @param role
* @param pageBean
* @return
*/
@RequestMapping(value="/list")
public String list(Model model, Role role, PageBean<Role> pageBean){
model.addAttribute("title", "角色列表");
model.addAttribute("name", role.getName());
model.addAttribute("pageBean", roleService.findByName(role, pageBean));
return "admin/role/list";
}
/**
* 角色添加页面
* @param model
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.GET)
public String add(Model model){
List<Menu> findAll = menuService.findAll();
model.addAttribute("topMenus", MenuUtil.getTopMenus(findAll));
model.addAttribute("secondMenus",MenuUtil.getSecondMenus(findAll));
model.addAttribute("thirdMenus",MenuUtil.getThirdMenus(findAll));
return "admin/role/add";
}
/**
* 角色添加表单提交处理
* @param role
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> add(Role role){
//用统一验证实体方法验证是否合法
CodeMsg validate = ValidateEntityUtil.validate(role);
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
if(roleService.save(role) == null){
return Result.error(CodeMsg.ADMIN_ROLE_ADD_ERROR);
}
log.info("添加角色【"+role+"】");
operaterLogService.add("添加角色【"+role.getName()+"】");
return Result.success(true);
}
/**
* 角色编辑页面
* @param id
* @param model
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.GET)
public String edit(@RequestParam(name="id",required=true)Long id,Model model){
List<Menu> findAll = menuService.findAll();
model.addAttribute("topMenus",MenuUtil.getTopMenus(findAll));
model.addAttribute("secondMenus",MenuUtil.getSecondMenus(findAll));
model.addAttribute("thirdMenus",MenuUtil.getThirdMenus(findAll));
Role role = roleService.find(id);
model.addAttribute("role", role);
model.addAttribute("authorities",JSONArray.toJSON(role.getAuthorities()).toString());
return "admin/role/edit";
}
/**
* 角色修改表单提交处理
* @param request
* @param role
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> edit(Role role){
//用统一验证实体方法验证是否合法
CodeMsg validate = ValidateEntityUtil.validate(role);
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
Role existRole = roleService.find(role.getId());
if(existRole == null){
return Result.error(CodeMsg.ADMIN_ROLE_NO_EXIST);
}
existRole.setName(role.getName());
existRole.setRemark(role.getRemark());
existRole.setStatus(role.getStatus());
existRole.setAuthorities(role.getAuthorities());
if(roleService.save(existRole) == null){
return Result.error(CodeMsg.ADMIN_ROLE_EDIT_ERROR);
}
log.info("编辑角色【"+role+"】");
operaterLogService.add("编辑角色【"+role.getName()+"】");
return Result.success(true);
}
/**
* 删除角色
* @param request
* @param id
* @return
*/
@RequestMapping(value="delete",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> delete(@RequestParam(name="id",required=true)Long id){
try {
roleService.delete(id);
} catch (Exception e) {
// TODO: handle exception
return Result.error(CodeMsg.ADMIN_ROLE_DELETE_ERROR);
}
log.info("编辑角色ID【"+id+"】");
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("/admin/order")
@Controller
public class OrderController {
@Autowired
private OrderService orderService;
@Autowired
private OrderItemService orderItemService;
/**
* 订单列表
* @param model
* @param order
* @param pageBean
* @return
*/
@RequestMapping(value="/list")
public String list(Model model, Order order, PageBean<Order> pageBean){
model.addAttribute("pageBean", orderService.findPage(order, pageBean));
model.addAttribute("sn",order.getSn());
return "admin/order/list";
}
/**
* 查看订单详情
* @param orderId
* @return
*/
@RequestMapping(value="/view_detail",method=RequestMethod.POST)
@ResponseBody
public Result<List<OrderItem>> viewDetail(@RequestParam(name="orderId",required=true)Long orderId){
return Result.success(orderItemService.find(orderId));
}
}
排片场次管理控制器:
/**
* 排片场次管理控制器
* @author yy
*
*/
@RequestMapping("/admin/cinema_hall_session")
@Controller
public class CinemaHallSessionController {
@Autowired
private CinemaService cinemaService;
@Autowired
private CinemaHallService cinemaHallService;
@Autowired
private MovieService movieService;
@Autowired
private CinemaHallSessionService cinemaHallSessionService;
/**
* 排片场次列表页面
* @param model
* @return
*/
@RequestMapping(value="/list")
public String list(Model model, CinemaHallSession cinemaHallSession, PageBean<CinemaHallSession> pageBean){
model.addAttribute("pageBean", cinemaHallSessionService.findPage(cinemaHallSession, pageBean));
model.addAttribute("showDate",cinemaHallSession.getShowDate());
return "admin/cinema_hall_session/list";
}
/**
* 排片场次添加页面
* @param model
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.GET)
public String add(Model model){
model.addAttribute("cinemaList", cinemaService.findAll());
model.addAttribute("movieList", movieService.findAll());
model.addAttribute("cinemaSessionTypeList", CinemaSessionType.values());
return "admin/cinema_hall_session/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("cinemaHallSession", cinemaHallSessionService.findById(id));
model.addAttribute("movieList", movieService.findAll());
model.addAttribute("cinemaList", cinemaService.findAll());
model.addAttribute("cinemaSessionTypeList", CinemaSessionType.values());
return "admin/cinema_hall_session/edit";
}
/**
* 添加排片场次表单提交
* @param cinemaHallSession
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> add(CinemaHallSession cinemaHallSession){
if(cinemaHallSession == null){
return Result.error(CodeMsg.DATA_ERROR);
}
CodeMsg validate = ValidateEntityUtil.validate(cinemaHallSession);
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
//判断是否是编辑
if(cinemaHallSession.getId() != null && cinemaHallSession.getId() > 0){
CinemaHallSession findById = cinemaHallSessionService.findById(cinemaHallSession.getId());
cinemaHallSession.setCreateTime(findById.getCreateTime());
}
//生成散场时间
String startTime = cinemaHallSession.getShowDate() + " " + cinemaHallSession.getShowTime();
cinemaHallSession.setStartTime(startTime);
cinemaHallSession.setEndTime(StringUtil.getFormatterDate(startTime, "yyyy-MM-dd HH:mm", Integer.valueOf(cinemaHallSession.getMovie().getTime())));
if(cinemaHallSessionService.isExistHall(cinemaHallSession.getId(),cinemaHallSession.getCinemaHall().getId(), cinemaHallSession.getShowDate(), startTime,cinemaHallSession.getEndTime())){
return Result.error(CodeMsg.ADMIN_CINEMA_HALL_SESSION_SAVE_EXIST);
}
//表示数据合法,可以保存到数据库
if(cinemaHallSessionService.save(cinemaHallSession) == null){
return Result.error(CodeMsg.ADMIN_CINEMA_HALL_SESSION_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 {
cinemaHallSessionService.delete(id);
} catch (Exception e) {
return Result.error(CodeMsg.ADMIN_CINEMA_HALL_SESSION_DELETE_ERROR);
}
return Result.success(true);
}
}
源码获取:博客首页 "资源" 里下载!
版权归原作者 pastclouds 所有, 如有侵权,请联系我们删除。