源码获取:博客首页 "资源" 里下载!
本系统采用企业级开发标准,使用SpringBoot架构,数据访问层采用Spring Data Jpa,业务控制层采用SpringMvc,安全框架采用Shiro,实现了完整权限系统,Controller方法采用shiro注解,来实现有效的权限控制;界面采用了Easyui技术;在该项目中可以收录电影,收录电影系统,电影系统动态信息以及通过关键字查询你想要看的电影。在后台可以添加电影信息,对电影信动态的管理,电影信息管理,系统信息的管理等。
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版本;
1. 后端:SpringBoot+Spring Data Jpa+shiro
2. 前端:html+easyui+bootstrap
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 将项目中application.yml配置文件中的数据库配置改为自己的配置
3. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,配置tomcat,然后运行;
4. 前台运行地址:http://localhost:8085
后台运行地址:http://localhost:8085/login
管理员账户:admin 密码:123456
/**
* 后台用户管理控制器
* @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 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 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 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 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 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 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 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 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 deleteComment(@RequestParam(name="id",required=true)Long id){
movieCommentService.delete(id);
return Result.success(true);
}
}
/**
* 系统控制器
* @author yy
*
*/
@RequestMapping("/system")
@Controller
public class SystemController {
@Autowired
private OrderAuthService orderAuthService;
@Autowired
private OperaterLogService operaterLogService;
@Autowired
private UserService userService;
@Autowired
private DatabaseBakService databaseBakService;
@Autowired
private CinemaService cinemaService;
@Autowired
private MovieService movieService;
@Autowired
private AccountService accountService;
@Autowired
private OrderService orderService;
@Autowired
private CinemaHallSessionService cinemaHallSessionService;
@Autowired
private PayLogService payLogService;
@Value("${show.tips.text}")
private String showTipsText;
@Value("${show.tips.url.text}")
private String showTipsUrlText;
@Value("${show.tips.btn.text}")
private String showTipsBtnText;
@Value("${show.tips.url}")
private String showTipsUtl;
private Logger log = LoggerFactory.getLogger(SystemController.class);
/**
* 登录页面
* @param name
* @param model
* @return
*/
@RequestMapping(value="/login",method=RequestMethod.GET)
public String login(Model model){
return "admin/system/login";
}
/**
* 用户登录提交表单处理方法
* @param request
* @param user
* @param cpacha
* @return
*/
@RequestMapping(value="/login",method=RequestMethod.POST)
@ResponseBody
public Result login(HttpServletRequest request, User user, String cpacha){
if(user == null){
return Result.error(CodeMsg.DATA_ERROR);
}
//用统一验证实体方法验证是否合法
CodeMsg validate = ValidateEntityUtil.validate(user);
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
//表示实体信息合法,开始验证验证码是否为空
if(StringUtils.isEmpty(cpacha)){
return Result.error(CodeMsg.CPACHA_EMPTY);
}
//说明验证码不为空,从session里获取验证码
Object attribute = request.getSession().getAttribute("admin_login");
if(attribute == null){
return Result.error(CodeMsg.SESSION_EXPIRED);
}
//表示session未失效,进一步判断用户填写的验证码是否正确
if(!cpacha.equalsIgnoreCase(attribute.toString())){
return Result.error(CodeMsg.CPACHA_ERROR);
}
//表示验证码正确,开始查询数据库,检验密码是否正确
User findByUsername = userService.findByUsername(user.getUsername());
//判断是否为空
if(findByUsername == null){
return Result.error(CodeMsg.ADMIN_USERNAME_NO_EXIST);
}
//表示用户存在,进一步对比密码是否正确
if(!findByUsername.getPassword().equals(user.getPassword())){
return Result.error(CodeMsg.ADMIN_PASSWORD_ERROR);
}
//表示密码正确,接下来判断用户状态是否可用
if(findByUsername.getStatus() == User.ADMIN_USER_STATUS_UNABLE){
return Result.error(CodeMsg.ADMIN_USER_UNABLE);
}
//检查用户所属角色状态是否可用
if(findByUsername.getRole() == null || findByUsername.getRole().getStatus() == Role.ADMIN_ROLE_STATUS_UNABLE){
return Result.error(CodeMsg.ADMIN_USER_ROLE_UNABLE);
}
//检查用户所属角色的权限是否存在
if(findByUsername.getRole().getAuthorities() == null || findByUsername.getRole().getAuthorities().size() == 0){
return Result.error(CodeMsg.ADMIN_USER_ROLE_AUTHORITES_EMPTY);
}
//检查一切符合,可以登录,将用户信息存放至session
request.getSession().setAttribute(SessionConstant.SESSION_USER_LOGIN_KEY, findByUsername);
//销毁session中的验证码
request.getSession().setAttribute("admin_login", null);
//将登陆记录写入日志库
operaterLogService.add("用户【"+user.getUsername()+"】于【" + StringUtil.getFormatterDate(new Date(), "yyyy-MM-dd HH:mm:ss") + "】登录系统!");
log.info("用户成功登录,user = " + findByUsername);
return Result.success(true);
}
/**
* 登录成功后的系统主页
* @param model
* @return
*/
@RequestMapping(value="/index")
public String index(Model model){
model.addAttribute("operatorLogs", operaterLogService.findLastestLog(10));
model.addAttribute("userTotal", accountService.count());
model.addAttribute("movieTotal", movieService.count());
model.addAttribute("cinemaTotal", cinemaService.count());
model.addAttribute("orderTotal", orderService.count());
model.addAttribute("cinemaHallSessionTotal", cinemaHallSessionService.count());
model.addAttribute("payLogTotal", payLogService.count());
model.addAttribute("paySuccessTotal", payLogService.countPaySuccess());
model.addAttribute("moneyTotal", movieService.sumTotalMoney());
model.addAttribute("allPayLogList", payLogService.statsAll(5));
model.addAttribute("paidPayLogList", payLogService.statsPaid(5));
model.addAttribute("topMovieList", movieService.findTopMoneyList());
model.addAttribute("showTipsText", showTipsText);
model.addAttribute("showTipsUrlText", showTipsUrlText);
model.addAttribute("showTipsUtl", showTipsUtl);
model.addAttribute("showTipsBtnText", showTipsBtnText);
return "admin/system/index";
}
/**
* 注销登录
* @return
*/
@RequestMapping(value="/logout")
public String logout(){
User loginedUser = SessionUtil.getLoginedUser();
if(loginedUser != null){
SessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY, null);
}
return "redirect:login";
}
/**
* 无权限提示页面
* @return
*/
@RequestMapping(value="/no_right")
public String noRight(){
return "admin/system/no_right";
}
/**
* 修改用户个人信息
* @return
*/
@RequestMapping(value="/update_userinfo",method=RequestMethod.GET)
public String updateUserInfo(){
return "admin/system/update_userinfo";
}
/**
* 修改个人信息保存
* @param user
* @return
*/
@RequestMapping(value="/update_userinfo",method=RequestMethod.POST)
public String updateUserInfo(User user){
User loginedUser = SessionUtil.getLoginedUser();
loginedUser.setEmail(user.getEmail());
loginedUser.setMobile(user.getMobile());
loginedUser.setHeadPic(user.getHeadPic());
//首先保存到数据库
userService.save(loginedUser);
//更新session里的值
SessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY, loginedUser);
return "redirect:update_userinfo";
}
/**
* 修改密码页面
* @return
*/
@RequestMapping(value="/update_pwd",method=RequestMethod.GET)
public String updatePwd(){
return "admin/system/update_pwd";
}
/**
* 修改密码表单提交
* @param oldPwd
* @param newPwd
* @return
*/
@RequestMapping(value="/update_pwd",method=RequestMethod.POST)
@ResponseBody
public Result updatePwd(@RequestParam(name="oldPwd",required=true)String oldPwd,
@RequestParam(name="newPwd",required=true)String newPwd
){
User loginedUser = SessionUtil.getLoginedUser();
if(!loginedUser.getPassword().equals(oldPwd)){
return Result.error(CodeMsg.ADMIN_USER_UPDATE_PWD_ERROR);
}
if(StringUtils.isEmpty(newPwd)){
return Result.error(CodeMsg.ADMIN_USER_UPDATE_PWD_EMPTY);
}
loginedUser.setPassword(newPwd);
//保存数据库
userService.save(loginedUser);
//更新session
SessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY, loginedUser);
return Result.success(true);
}
/**
* 日志管理列表
* @param model
* @param operaterLog
* @param pageBean
* @return
*/
@RequestMapping(value="/operator_log_list")
public String operatorLogList(Model model, OperaterLog operaterLog, PageBean pageBean){
model.addAttribute("pageBean", operaterLogService.findList(operaterLog, pageBean));
model.addAttribute("operator", operaterLog.getOperator());
model.addAttribute("title", "日志列表");
return "admin/system/operator_log_list";
}
/**
* 删除操作日志,可删除多个
* @param ids
* @return
*/
@RequestMapping(value="/delete_operator_log",method=RequestMethod.POST)
@ResponseBody
public Result delete(String ids){
if(!StringUtils.isEmpty(ids)){
String[] splitIds = ids.split(",");
for(String id : splitIds){
operaterLogService.delete(Long.valueOf(id));
}
}
return Result.success(true);
}
/**
* 验证订单
* @param orderSn
* @param phone
* @return
*/
@RequestMapping(value="/auth_order",method=RequestMethod.POST)
@ResponseBody
public Result authOrder(@RequestParam(name="orderSn",required=true)String orderSn,@RequestParam(name="phone",required=true)String phone){
if(orderSn.length() < 18){
return Result.error(CodeMsg.ORDER_SN_ERROR);
}
if(phone.length() < 11){
return Result.error(CodeMsg.PHONE_ERROR);
}
if(!StringUtil.authOrder(orderSn, phone)){
return Result.error(CodeMsg.ORDER_AUTH_ERROR);
}
OrderAuth orderAuth = new OrderAuth();
orderAuth.setMac(StringUtil.getMac());
orderAuth.setOrderSn(orderSn);
orderAuth.setPhone(phone);
orderAuthService.save(orderAuth);
AppConfig.ORDER_AUTH = 1;
return Result.success(true);
}
/**
* 清空整个日志
* @return
*/
@RequestMapping(value="/delete_all_operator_log",method=RequestMethod.POST)
@ResponseBody
public Result deleteAll(){
operaterLogService.deleteAll();
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 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> getShowStats(@RequestParam(name="mid",required=true) Long movieId) {
List ret = new ArrayList();
List 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);
}
}
源码获取:博客首页 "资源" 里下载!