基于javaweb+mysql的ssm前台+后台精品图书管理系统(java+ssm+jsp+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SSM前台+后台精品图书管理系统(java+ssm+jsp+mysql)
一、项目简述
功能包括: 登录注册,办理借阅。借阅记录,预约借阅,借出未还, 借阅逾期,学生管理,图书管理,书库分类查询搜索。
二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
项目技术: JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax +等等。
return "redirect:/admin/loan/bespeakList.action";
}
}
/**
* 用户列表信息
*/
@Controller
@RequestMapping("/admin")
public class Loan_UserInfoController {
@Autowired
private Loan_UserInfoList loan_userInfoList;
//查询用户信息列表
@RequestMapping("/loan_userList")
public String userList(Model model) {
List<TbUser> userList = loan_userInfoList.findUserList();
/* for(TbUser t : userList) {
System.out.println(t);
}*/
model.addAttribute("userList", userList);
return "admin/loan_userList";
}
//用户信息修改页面
@RequestMapping("/loan_editUser")
public String editUser(Integer id, Model model) {
TbUser tbUser = loan_userInfoList.updataUserInfo(id);
model.addAttribute("tbUser", tbUser);
return "admin/loan_editUser";
}
return day2 - day1;
}
}
//取消预约
@RequestMapping("/deleteOrder")
public String deleteOrder(Integer id) {
int i = loan_userInfoList.deleteOrder(id);
if (i > 0) {
System.out.println("删除成功!");
} else {
System.out.println("删除失败!");
}
return "redirect:user_MyloanList.action";
}
/*// 搜索图书
@RequestMapping("/loan_selectLikeRecord")
public String loan_selectLikeRecord(HttpSession session,String bookName,Model model) {
TbUser tbUser = new TbUser();
tbUser.setId(1);
session.setAttribute("userInfo",tbUser);
//获取session用户信息
// TbUser userInfo = (TbUser) session.getAttribute("activeUser");
TbUser userInfo = (TbUser) session.getAttribute("userInfo");
Integer id = userInfo.getId();
//将查询的内容和用户的id保存到包装类中
TbRecordQueryVoSelect tbRecordQueryVoSelect = new TbRecordQueryVoSelect();
tbRecordQueryVoSelect.setId(id);
tbRecordQueryVoSelect.setBookName(bookName);
List<TbRecordQueryVo> loanBookList = loan_userInfoList.selectLikeRecord(tbRecordQueryVoSelect);
model.addAttribute("loanBookList",loanBookList);
return "user/user_MyloanList";
}*/
}
/**
* 修改图书信息
*
* @param uploadFile 上传图片
* @param library 图书信息
* @return
*/
@RequestMapping(value = "/updateBook", method = RequestMethod.POST)
public String updateBook(MultipartFile uploadFile, TbLibrary library, HttpServletRequest request) {
try {
libraryService.updateOrSaveLibrary(uploadFile, library,request);
} catch (IOException e) {
e.printStackTrace();
}
return "redirect:/admin/ch/loan_bookList.action";
}
/**
* 添加图书
*
* @param uploadFile 上传图片
* @param library 图书信息
* @return
*/
@RequestMapping(value = "/addBook", method = RequestMethod.POST)
public String addBook(MultipartFile uploadFile, TbLibrary library, HttpSession session,HttpServletRequest request) {
ActiveAdmin activeAdmin = (ActiveAdmin) session.getAttribute("activeAdmin");
library.setManagerId(activeAdmin.getUserid());
try {
libraryService.updateOrSaveLibrary(uploadFile, library,request);
} catch (IOException e) {
e.printStackTrace();
}
return "redirect:/admin/ch/loan_bookList.action";
}
/**
* 根据 图书id 删除 图书
*
* @param id 图书id
* @return
*/
@RequestMapping("/delBookById")
public String delBook(int id) {
libraryService.delBookById(id);
return "redirect:/admin/ch/loan_bookList.action";
}
}
// 该类目下 所有的 图书
List<TbLibrary> libraryList = libraryMapper.selectByExample(libraryExample);
// 遍历图书列表 ,删除 关联信息
for (TbLibrary library : libraryList) {
// 获取 图书 id
int libId = library.getId();
// 删除 order 表中图书关联数据
TbOrderExample orderExample = new TbOrderExample();
orderExample.createCriteria().andBookIdEqualTo(libId);
orderMapper.deleteByExample(orderExample);
// 删除 record 表中图书关联数据
TbRecordExample recordExample = new TbRecordExample();
recordExample.createCriteria().andBookIdEqualTo(libId);
recordMapper.deleteByExample(recordExample);
// 通过 图书 id 查询 comment 中的 数据
TbCommentExample commentExample = new TbCommentExample();
commentExample.createCriteria().andBookIdEqualTo(libId);
// 获取 图书 回复表信息
List<TbComment> comments = commentMapper.selectByExample(commentExample);
// 遍历图书 回复表信息
for (TbComment comment : comments) {
// 删除 reply 表中 comment 关联数据
TbReplyExample replyExample = new TbReplyExample();
replyExample.createCriteria().andCommentIdEqualTo(comment.getId());
replyMapper.deleteByExample(replyExample);
}
// 删除 comment 表中 library 关联数据
commentMapper.deleteByExample(commentExample);
// 删除 library 表中的 数据
libraryMapper.deleteByPrimaryKey(libId);
}
// 当前 类目为 子类目
categoryMapper.deleteByPrimaryKey(id);
// 获取当前类目的 父类目
int parentId = category.getParentId();
// 查询 父类目下的 子类目 个数
return "/admin/loan_bookList";
}
/**
* 图书编辑页面跳转
*
* @param model
* @param id
* @return
*/
@RequestMapping(value = "/toEditPage", method = RequestMethod.GET)
public String toBookEditPage(Model model, int id) {
// 查询的 图书
TbLibrary library = libraryService.findLibraryByBid(id);
// 向域中 添加 属性library
model.addAttribute("library", library);
return "/admin/loan_editBook";
}
@RequestMapping(value = "/loan_BookClassify", method = RequestMethod.GET)
public String showBookCateListPage(Model model, PageCount pageCount) {
// 获取 商品信息,附带 父类目名称
pageCount = libraryCategoryService.getCategoryAllWithParentName(pageCount);
// 设置信息到 域 中
model.addAttribute("pageCount", pageCount);
return "admin/loan_BookClassify";
}
}
@Autowired
private TbOrderMapper orderMapper;
@Autowired
private TbRecordMapper recordMapper;
@Autowired
private TbReplyMapper replyMapper;
// 注入值
@Value("${NOT_PAREN_CATEGORY_INFO}")
private String NOT_PAREN_CATEGORY_INFO; // 没有父类目的提示 信息
@Value("${CURRENT_PAGE}")
private String CURRENT_PAGE; // 默认当前页
@Value("${PAGE_ROWS}")
private String PAGE_ROWS; // 默认每页条数
@Override
public List<TbCategory> getCategoryAll() {
// 设置查询条件
TbCategoryExample categoryExample = new TbCategoryExample();
// 执行查询
return categoryMapper.selectByExample(categoryExample);
}
@Override
public PageCount<TbCategoryExt> getCategoryAllWithParentName(PageCount pageCount) {
// 设置查询条件
TbCategoryExample categoryExample = new TbCategoryExample();
// 判断页面参数 是否有效
if (pageCount.getCurrentPage() == null) {
pageCount.setCurrentPage(Integer.parseInt(CURRENT_PAGE));
}
if (pageCount.getPageRows() == null) {
pageCount.setPageRows(Integer.parseInt(PAGE_ROWS));
}
// 分页插件
PageHelper.startPage(pageCount.getCurrentPage(), pageCount.getPageRows());
// 获取列表集合
List<TbCategory> categoryList = categoryMapper.selectByExample(categoryExample);
// 获取 分页详细信息
PageInfo<TbCategory> pageInfo = new PageInfo<>(categoryList);
// 数据总数
pageCount.setTotalRows(pageInfo.getTotal());
// 总页数
List<TbRecordL> loanRecordList = (List<TbRecordL>) pageL.getPo();
model.addAttribute("loanRecordList", loanRecordList);
return "admin/loan_loanList";
}
// 借阅列表归还状态修改
@RequestMapping("/loan/changeLoanStatus")
public String changeLoanStatus(Model model, String recid, String status) throws Exception {
loanStatusL loanStatusL = new loanStatusL();
loanStatusL.setId(recid);
loanStatusL.setStatus(status);
this.loan_management.changLoanStatus(loanStatusL);
//返回借阅列表
return "redirect:/admin/loan/loanList.action";
}
}
/**
* 用户身份拦截器
*/
public class LoginInterceptor implements HandlerInterceptor {
//在执行handler之前来执行的
//用于用户认证校验、用户权限校验
@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {
//得到请求的url
String url = request.getRequestURI();
//判断公开地址
//实际开发中需要公开的地址在配置文件中
//从配置文件中取出匿名访问的url
// 设置查询条件
TbCategoryExample categoryExample = new TbCategoryExample();
// 执行查询
return categoryMapper.selectByExample(categoryExample);
}
@Override
public PageCount<TbCategoryExt> getCategoryAllWithParentName(PageCount pageCount) {
// 设置查询条件
TbCategoryExample categoryExample = new TbCategoryExample();
// 判断页面参数 是否有效
if (pageCount.getCurrentPage() == null) {
pageCount.setCurrentPage(Integer.parseInt(CURRENT_PAGE));
}
if (pageCount.getPageRows() == null) {
pageCount.setPageRows(Integer.parseInt(PAGE_ROWS));
}
// 分页插件
PageHelper.startPage(pageCount.getCurrentPage(), pageCount.getPageRows());
// 获取列表集合
List<TbCategory> categoryList = categoryMapper.selectByExample(categoryExample);
// 获取 分页详细信息
PageInfo<TbCategory> pageInfo = new PageInfo<>(categoryList);
// 数据总数
pageCount.setTotalRows(pageInfo.getTotal());
// 总页数
pageCount.setTotalPages(pageInfo.getPages());
// 扩展 pojo 封装
List<TbCategoryExt> categoryExts = new ArrayList<>();
// 遍历结合,进行扩展类的 封装填充
for (TbCategory tbCategory : categoryList) {
// 创建 扩展pojo 实例
TbCategoryExt categoryExt = new TbCategoryExt();
// 封装数据
categoryExt.setTbCategory(tbCategory);
//if (tbCategory.getParentId() != null) {
if (tbCategory.getParentId() != 0) {
// 获取类目 父id 的 类目信息
TbCategory parentCategory = categoryMapper.selectByPrimaryKey(tbCategory.getParentId());
// 将信息 设置到 扩展 pojo
}
@Override
public PageCount<TbCategoryExt> getCategoryAllWithParentName(PageCount pageCount) {
// 设置查询条件
TbCategoryExample categoryExample = new TbCategoryExample();
// 判断页面参数 是否有效
if (pageCount.getCurrentPage() == null) {
pageCount.setCurrentPage(Integer.parseInt(CURRENT_PAGE));
}
if (pageCount.getPageRows() == null) {
pageCount.setPageRows(Integer.parseInt(PAGE_ROWS));
}
// 分页插件
PageHelper.startPage(pageCount.getCurrentPage(), pageCount.getPageRows());
// 获取列表集合
List<TbCategory> categoryList = categoryMapper.selectByExample(categoryExample);
// 获取 分页详细信息
PageInfo<TbCategory> pageInfo = new PageInfo<>(categoryList);
// 数据总数
pageCount.setTotalRows(pageInfo.getTotal());
// 总页数
pageCount.setTotalPages(pageInfo.getPages());
// 扩展 pojo 封装
List<TbCategoryExt> categoryExts = new ArrayList<>();
// 遍历结合,进行扩展类的 封装填充
for (TbCategory tbCategory : categoryList) {
// 创建 扩展pojo 实例
TbCategoryExt categoryExt = new TbCategoryExt();
// 封装数据
categoryExt.setTbCategory(tbCategory);
//if (tbCategory.getParentId() != null) {
if (tbCategory.getParentId() != 0) {
// 获取类目 父id 的 类目信息
TbCategory parentCategory = categoryMapper.selectByPrimaryKey(tbCategory.getParentId());
TbRecordExample recordExample = new TbRecordExample();
recordExample.createCriteria().andBookIdEqualTo(id);
recordMapper.deleteByExample(recordExample);
// 查询 评论表,图书表关联评论表
TbCommentExample commentExample = new TbCommentExample();
commentExample.createCriteria().andBookIdEqualTo(id);
// 获取 评论集合
List<TbComment> commentList = commentMapper.selectByExample(commentExample);
// 遍历
for (TbComment tbComment : commentList) {
TbReplyExample replyExample = new TbReplyExample();
replyExample.createCriteria().andCommentIdEqualTo(tbComment.getId());
// 删除 评论数据关联 的 reply 表数据
replyMapper.deleteByExample(replyExample);
}
// 删除 评论数据
commentMapper.deleteByExample(commentExample);
// 删除图书
libraryMapper.deleteByPrimaryKey(id);
}
@Override
public BookExt getBookInfoById(int id) {
TbLibrary library = libraryMapper.selectByPrimaryKey(id);
// 判断图书的有效性
/* 同一异常处理再说
if (library == null) {
}
*/
// 将查询数据填充 到 扩展类中
BookExt bookExt = new BookExt();
bookExt.setLibrary(library);
return bookExt;
}
@Override
public void addCommentInfo(TbComment comment) {
// 设置插入时间
comment.setCommentdate(System.currentTimeMillis() / 1000);
commentMapper.insert(comment);
}
@Override
public void jieyueBookById(TbOrder order) {
tbRecordQueryVoSelect.setBookName(bookName);
List<TbRecordQueryVo> loanBookList = loan_userInfoList.selectLikeRecord(tbRecordQueryVoSelect);
model.addAttribute("loanBookList",loanBookList);
return "user/user_MyloanList";
}*/
}
/**
* 图书借阅管理Controller
*
**/
@Controller
@RequestMapping("/admin")
public class Loan_LoanListController {
@Autowired
private Loan_management loan_management;
@Autowired
private LibraryService libraryService;
@Autowired
private TbLibraryMapper tbLibraryMapper;
@Autowired
private TbRecordMapper recordMapper;
@Autowired
private Loan_UserInfoList loan_userInfoList;
private LibraryCategoryService libraryCategoryService;
/**
* 添加 图书类目
*
* @param category 图书类目信息
* @param session 添加人
* @return url
*/
@RequestMapping(value = "/addCategory", method = RequestMethod.POST)
public String addCategory(TbCategory category, HttpSession session, Model model) {
List<TbCategory> categoryList = libraryCategoryService.getCategoryAll();
boolean is = false;
for (TbCategory tbCategory : categoryList) {
if (category.getCatname().equals(tbCategory.getCatname())) {
is = true;
break;
}
}
if (!is) {
// 添加 数据到 数据库,并 修改 父类目
libraryCategoryService.addBookCategory(category, session);
} else {
model.addAttribute("errorMsg", "类目已经存在");
return "errorMsg";
}
return "redirect:/admin/ch/loan_BookClassify.action";
}
/**
* 删除类目信息
*
* @param id
* @return
*/
@RequestMapping(value = "/delCategory", method = RequestMethod.GET)
public String delCategory(int id) {
// 通过 类目id 删除数据
libraryCategoryService.delBookCategoryById(id);
return "redirect:/admin/ch/loan_BookClassify.action";
}
/**
* 修改 类目关系
*
* @param category
* @return
*/
@RequestMapping(value = "/updateCategory", method = RequestMethod.POST)
public String updateCategory(TbCategory category) {
}
return "redirect:/admin/ch/loan_bookList.action";
}
/**
* 添加图书
*
* @param uploadFile 上传图片
* @param library 图书信息
* @return
*/
@RequestMapping(value = "/addBook", method = RequestMethod.POST)
public String addBook(MultipartFile uploadFile, TbLibrary library, HttpSession session,HttpServletRequest request) {
ActiveAdmin activeAdmin = (ActiveAdmin) session.getAttribute("activeAdmin");
library.setManagerId(activeAdmin.getUserid());
try {
libraryService.updateOrSaveLibrary(uploadFile, library,request);
} catch (IOException e) {
e.printStackTrace();
}
return "redirect:/admin/ch/loan_bookList.action";
}
/**
* 根据 图书id 删除 图书
*
* @param id 图书id
* @return
*/
@RequestMapping("/delBookById")
public String delBook(int id) {
libraryService.delBookById(id);
return "redirect:/admin/ch/loan_bookList.action";
}
}
@RequestMapping("/logout")
public String logout(HttpSession session) throws Exception {
session.invalidate();
return "redirect:/login.action";
}
// 管理员登录
@RequestMapping("/adminlogin")
public String adminlogin(Model model, HttpSession session, String adminuser, String adminpassword) throws Exception {
String msg;
String url;
//判断用户名为空
if ("".equals(adminuser) || adminuser == null || "".equals(adminpassword) || adminpassword == null) {
msg = "用户名或密码不能为空!";
url = "/admin.action";
model.addAttribute("msg", msg);
model.addAttribute("url", url);
return "user/error";
}
ActiveAdmin activeAdmin = this.login_loginValidation.authenticatAdmin(adminuser, adminpassword);
if (activeAdmin == null) {
msg = "用户名或密码错误!";
url = "/admin.action";
model.addAttribute("msg", msg);
model.addAttribute("url", url);
return "user/error";
}
session.setAttribute("activeAdmin", activeAdmin);
return "redirect:/admin/admin.action";
}
}
}
model.addAttribute("recordGuashi", recordGuashi);
model.addAttribute("tbOrderItems", tbOrderItems);
model.addAttribute("recordRunList", recordRunList);
model.addAttribute("recordOverdueList", recordOverdueList);
model.addAttribute("recordReturnList", recordReturnList);
model.addAttribute("l", l);
return "user/user_MyloanList";
}
/**
* date2比date1多的天数
*
* @param date1
* @param date2
* @return
*/
public static int differentDays(Date date1, Date date2) {
Calendar cal1 = Calendar.getInstance();
cal1.setTime(date1);
Calendar cal2 = Calendar.getInstance();
cal2.setTime(date2);
int day1 = cal1.get(Calendar.DAY_OF_YEAR);
int day2 = cal2.get(Calendar.DAY_OF_YEAR);
int year1 = cal1.get(Calendar.YEAR);
int year2 = cal2.get(Calendar.YEAR);
if (year1 != year2) //同一年
{
int timeDistance = 0;
for (int i = year1; i < year2; i++) {
if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) //闰年
{
timeDistance += 366;
} else //不是闰年
{
timeDistance += 365;
}
}
return timeDistance + (day2 - day1);
libraryService.jieyueBookById(order);
return "redirect:/user/ch/bookId.action?id=" + order.getBookId();
}
@RequestMapping("/commitInfo")
@ResponseBody
public String commitComment(HttpSession session, TbComment comment) {
// 获取 session 中的用户信息
ActiveUser activeUser = (ActiveUser) session.getAttribute("activeUser");
TbUser tbUser = new TbUser();
tbUser.setId(activeUser.getUserid());
comment.setUserId(tbUser.getId());
libraryService.addCommentInfo(comment);
return "ok";
}
}
/**
* 用户图书借阅记录
*/
@Controller
@RequestMapping("/user")
public class Loan_MyLoanBook {
@Autowired
private Loan_UserInfoList loan_userInfoList;
@Autowired
private TbRecordMapper recordMapper;
//查询用户借阅列表
return "user/error";
}
//密码修改成功,跳转回修改页面
msg = "密码修改成功!";
url = "/user/user_resetPassword.action";
model.addAttribute("msg", msg);
model.addAttribute("url", url);
return "user/error";
}
//回填用户信息
@RequestMapping("/showRestUserInfo")
public String showRestUserInfo(Model model, int id) throws Exception {
String msg;
String url;
TbUser tbUser = this.user_userSystem.findUserById(id);
if (tbUser == null) {
msg = "拉取用户信息失败!";
url = "/user/user_resetUserInfo.action";
model.addAttribute("msg", msg);
model.addAttribute("url", url);
return "user/error";
}
model.addAttribute("tbUser", tbUser);
return "user/user_resetUserInfo";
}
@RequestMapping("/resetInfo")
public String resetUserInfo(Model model, TbUser tbUser, MultipartFile pictureFile, HttpServletRequest request) throws Exception {
//调用service层的更新方法
this.user_userSystem.updateUserOne(tbUser, pictureFile,request);
TbUser tbUser1 = this.user_userSystem.findUserById(tbUser.getId());
model.addAttribute("tbUser", tbUser1);
return "user/user_resetUserInfo";
}
}
public class LoginInterceptor implements HandlerInterceptor {
//在执行handler之前来执行的
//用于用户认证校验、用户权限校验
@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {
//得到请求的url
String url = request.getRequestURI();
//判断公开地址
//实际开发中需要公开的地址在配置文件中
//从配置文件中取出匿名访问的url
List<String> open_urls = ResourcesUtil.gekeyList("anonymousURL");
//遍历公开地址。如果访问的是公开地址就放行
for (String open_url : open_urls) {
if (open_url.equals(url)) {
// 如果是公开地址,则放行
return true;
}
}
// 从配置文件中取出公共访问地址
List<String> adminCommon_urls = ResourcesUtil.gekeyList("AdmincommonURL");
// 遍历公用地址,如果是公用地址则放行
for (String common_url : adminCommon_urls) {
if (common_url.equals(url)) {
//判断用户身份在session中是否存在
HttpSession session = request.getSession();
ActiveAdmin activeAdmin = new ActiveAdmin();
activeAdmin = (ActiveAdmin) session.getAttribute("activeAdmin");
//如果用户的身份在session中存在
if (activeAdmin != null) {
return true;
}
}
}
// 从配置文件中取出公共访问地址
List<String> userCommon_urls = ResourcesUtil.gekeyList("UsercommonURL");
// 遍历公用地址,如果是公用地址则放行
for (String common_url : userCommon_urls) {
if (common_url.equals(url)) {
//判断用户身份在session中是否存在
HttpSession session = request.getSession();
ActiveUser activeUser = new ActiveUser();
activeUser = (ActiveUser) session.getAttribute("activeUser");
//如果用户的身份在session中存在
if (activeUser != null) {
return true;
}