基于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 +等等。
/**
* 用户黑名单
*/
@Controller
@RequestMapping("/admin")
public class Loan_UserOnlineController {
@Autowired
private Loan_UserInfoList loan_userInfoList;
//查询黑名单列表
@RequestMapping("/loan_blackList")
public String loan_blackList(Model model) {
List<TbUser> userByOnline = loan_userInfoList.findUserByOnline(1);
/* for(TbUser t : userByOnline) {
System.out.println(t);
}*/
model.addAttribute("userByOnline", userByOnline);
return "admin/loan_blackList";
}
//用户列表模糊查询用户信息(用户名)
@RequestMapping("/loan_selectLikeOnline")
public String Loan_selectLikeName(TbUser tbUser, Model model) {
Integer online = 1;
TbUserQueryVo tbUserQueryVo = new TbUserQueryVo();
tbUserQueryVo.setTbUser(tbUser);
tbUserQueryVo.setOnline(online);
List<TbUser> userByOnline = loan_userInfoList.selectLikeName(tbUserQueryVo);
model.addAttribute("userByOnline", userByOnline);
return "admin/loan_blackList";
}
//用户删除
@RequestMapping("/loan_deleteUserOnline")
public String loan_deleteUser(Integer id) {
int i = loan_userInfoList.deleteUser(id);
if (i > 0) {
return "redirect:loan_blackList.action";
}
return "redirect:loan_blackList.action";
}
//恢复黑名单
@RequestMapping("/loan_recoverUserOnline")
// 判断 该类目是否是 父类目
if (category.getIsParent()) {
// 查询 当前类目的 子id
// 创建查询条件
TbCategoryExample categoryExample = new TbCategoryExample();
categoryExample.createCriteria().andParentIdEqualTo(category.getId());
// 进行 查询
List<TbCategory> categoryList = categoryMapper.selectByExample(categoryExample); // 子类目
// 遍历 删除子类目
for (TbCategory tbCategory : categoryList) {
delBookCategoryById(tbCategory.getId());
}
}
// 获取 该 类目 下的 所有图书
TbLibraryExample libraryExample = new TbLibraryExample();
// 添加 条件
libraryExample.createCriteria().andCateIdEqualTo(id);
// 该类目下 所有的 图书
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);
// 按照条件进行查询
PageCount<TblibraryExt> libraryPageCount = libraryService.findLibraryByAll(libraryQuery, pageCount);
// model 将数据设置到域中
model.addAttribute("subCategoryList", categoryList);
model.addAttribute("libraryPageCount", libraryPageCount);
// 默认
if (currentCategory == null) {
currentCategory = new TbCategory();
currentCategory.setId(0);
}
session.setAttribute("currentCategory", currentCategory.getId());
return "/user/user_bookList";
}
/**
* 通过 图书 id 查询 图书详细信息
*
* @param id
* @return
*/
@RequestMapping("/bookId")
public String toBookInfo(int id, Model model) {
BookExt bookInfo = libraryService.getBookInfoById(id);
// 将 时间戳 进行转换
Long dateSS = bookInfo.getLibrary().getCreatedate();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
String formatDate = simpleDateFormat.format(new Date(dateSS * 1000));
bookInfo.setFormatDate(formatDate);
// 通过 图书id 获取 回复信息
List<CommentExt> commentExts = commentService.findCommentByBookId(id);
// 将 查询的 图书信息 设置到 域 中
model.addAttribute("bookInfo", bookInfo);
// 将 回复信息 设置到 域 汇总
model.addAttribute("commentExts", commentExts);
return "/user/bookDetail";
}
/**
* 用于 借阅 图书 操作
*
* @param session 用于 取 用户信息
* @param order 用户借阅关联信息
* @return
*/
@RequestMapping("/jieyue_book")
public String jieyueBook(HttpSession session, Model model, String oid, String kkid, TbOrder order) {
} else //不同年
{
System.out.println("判断day2 - day1 : " + (day2 - day1));
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";
}*/
}
@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());
// 总页数
pageCount.setTotalPages(pageInfo.getPages());
/**
* @description: 图书类别处理
*/
@Controller
@RequestMapping("/admin/ch/category")
public class CategoryController {
//注入
@Autowired
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);
}
// 添加到集合中
categoryExts.add(categoryExt);
}
// 将 集合 设置到 pageCount
pageCount.setContentList(categoryExts);
return pageCount;
}
@Override
public void addBookCategory(TbCategory category, HttpSession session) {
/*
// 设置添加人
TbUser admin = (TbUser) session.getAttribute("loginAdmin");
// 设置添加人id
category.setManagerId(admin.getId());*/
category.setManagerId(1); // 测试
// 设置添加时间
category.setCreatedate(System.currentTimeMillis() / 1000);
// 设置 是否为 父
category.setIsParent(false);
// 获取 添加 类目的 父类目
int parentId = category.getParentId();
if (parentId != 0) {
// 创建 父类目 对象
TbCategory parentCategory = new TbCategory();
parentCategory.setId(parentId);
parentCategory.setIsParent(true);
// 修改父类目的 isParent 值
categoryMapper.updateByPrimaryKeySelective(parentCategory);
}
//添加当前类目
categoryMapper.insert(category);
}
return "user/user_resetUserInfo";
}
}
/**
* @desc 借阅逾期列表
**/
@Controller
@RequestMapping("/admin")
public class Loan_LoanOutTimeController {
@Autowired
private Loan_management loan_management;
@RequestMapping("/loan/outTimeList")
public String outTimeList(Model model, Integer currentPage) throws Exception {
LoanOutTimeL loanOutTimeL = new LoanOutTimeL();
//如果传入的有页面
if (currentPage != null) {
loanOutTimeL.setCurrentPage(currentPage);
}
//查询数据和分页,并返回
pageL pageL = this.loan_management.findOutTimeList(loanOutTimeL);
List<LoanOutTimeL> outTimeList = (List<LoanOutTimeL>) pageL.getPo();
model.addAttribute("pageL", pageL);
model.addAttribute("outTimeList", outTimeList);
return "admin/loan_outtime";
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_BookClassify.action";
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";
}*/
}
* 根据 图书id 删除 图书
*
* @param id 图书id
* @return
*/
@RequestMapping("/delBookById")
public String delBook(int id) {
libraryService.delBookById(id);
return "redirect:/admin/ch/loan_bookList.action";
}
}
/**
* 用户黑名单
*/
@Controller
@RequestMapping("/admin")
public class Loan_UserOnlineController {
@Autowired
private Loan_UserInfoList loan_userInfoList;
//查询黑名单列表
@RequestMapping("/loan_blackList")
public String loan_blackList(Model model) {
List<TbUser> userByOnline = loan_userInfoList.findUserByOnline(1);
/* for(TbUser t : userByOnline) {
System.out.println(t);
}*/
model.addAttribute("userByOnline", userByOnline);
return "admin/loan_blackList";
}
}
@Override
public void delBookCategoryById(int id) {
// 通过 id 查询该 类目的 信息
TbCategory category = categoryMapper.selectByPrimaryKey(id);
// 判断 该类目是否是 父类目
if (category.getIsParent()) {
// 查询 当前类目的 子id
// 创建查询条件
TbCategoryExample categoryExample = new TbCategoryExample();
categoryExample.createCriteria().andParentIdEqualTo(category.getId());
// 进行 查询
List<TbCategory> categoryList = categoryMapper.selectByExample(categoryExample); // 子类目
// 遍历 删除子类目
for (TbCategory tbCategory : categoryList) {
delBookCategoryById(tbCategory.getId());
}
}
// 获取 该 类目 下的 所有图书
TbLibraryExample libraryExample = new TbLibraryExample();
// 添加 条件
libraryExample.createCriteria().andCateIdEqualTo(id);
// 该类目下 所有的 图书
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();
public List<TbCategory> getCategoryByCid(int cid) {
// 若 当前 类目id 为 0
if (cid == 0) {
TbCategoryExample categoryExample = new TbCategoryExample();
return categoryMapper.selectByExample(categoryExample);
}
// 根据 类目id 获取 类目信息
TbCategory category = categoryMapper.selectByPrimaryKey(cid);
// 判断该 图书是否是 父类目
if (category.getIsParent()) {
// 获取 父类目 为当前 类目 的 所有 类目
TbCategoryExample categoryExample = new TbCategoryExample();
categoryExample.createCriteria().andParentIdEqualTo(cid);
return categoryMapper.selectByExample(categoryExample);
}
int parentId = 0;
// 获取当前类目的 父类目
if (category.getParentId() != null) {
parentId = category.getParentId();
}
// 获取 父类目下所有的 子类目信息
TbCategoryExample categoryExample = new TbCategoryExample();
categoryExample.createCriteria().andParentIdEqualTo(parentId);
return categoryMapper.selectByExample(categoryExample);
}
}
}
/**
* @desc 借出未还
**/
@Controller
@RequestMapping("/admin")
public class Loan_LoanOutStandingController {
@Autowired
private Loan_management loan_management;
//数据列表
@RequestMapping("/loan/outStanding")
public String outStanding(Model model, Integer currentPage) throws Exception {
TbOrderL tbOrderL = new TbOrderL();
//如果传入的有页面
if (currentPage != null) {
tbOrderL.setCurrentPage(currentPage);
}
//查询数据和分页,并返回
pageL pageL = this.loan_management.getLoanOutStanding(tbOrderL);
List<TbRecordL> outStandingList = (List<TbRecordL>) pageL.getPo();
model.addAttribute("pageL", pageL);
model.addAttribute("outStandingList", outStandingList);
return "admin/loan_outstanding";
}
// 数据搜索
@RequestMapping("/loan/searchOutStanding")
public String searchOutStanding(Model model, String searchSelect, String searchKeyWord, Integer currentPage) throws Exception {
TbOrderL tbOrderL = new TbOrderL();
//如果传入的有页面
if (currentPage != null) {
tbOrderL.setCurrentPage(currentPage);
}
//实例化包装类(包装类中在原有类的基础上添加的column(列名称)和keyword(搜索关键字)两个字段)
tbOrderL.setColumn(searchSelect);
/**
*
* @description: 图书类目 服务接口实现类
*
*/
@Service
public class LibraryCategoryServiceImpl implements LibraryCategoryService {
//注入 服务接口
@Autowired
private TbCategoryMapper categoryMapper;
@Autowired
private TbLibraryMapper libraryMapper;
@Autowired
private TbCommentMapper commentMapper;
@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; // 默认当前页
*/
@Controller
@RequestMapping("/admin/ch/category")
public class CategoryController {
//注入
@Autowired
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) {
model.addAttribute("pageL", pageL);
model.addAttribute("outStandingList", outStandingList);
return "admin/loan_outstanding";
}
// 数据搜索
@RequestMapping("/loan/searchOutStanding")
public String searchOutStanding(Model model, String searchSelect, String searchKeyWord, Integer currentPage) throws Exception {
TbOrderL tbOrderL = new TbOrderL();
//如果传入的有页面
if (currentPage != null) {
tbOrderL.setCurrentPage(currentPage);
}
//实例化包装类(包装类中在原有类的基础上添加的column(列名称)和keyword(搜索关键字)两个字段)
tbOrderL.setColumn(searchSelect);
tbOrderL.setKeyWord(searchKeyWord);
//将查询结果保存到list集合并通过model将对象集合放入request域中
//查询数据和分页,并返回
pageL pageL = this.loan_management.getLoanOutStanding(tbOrderL);
List<TbRecordL> outStandingList = (List<TbRecordL>) pageL.getPo();
model.addAttribute("pageL", pageL);
model.addAttribute("outStandingList", outStandingList);
return "admin/loan_outstanding";
}
// 归还图书
@RequestMapping("/loan/returnBook")
public String returnBook(Model model, String id) throws Exception {
//将借阅id和状态码存入 扩展类中
loanStatusL loanStatusL = new loanStatusL();
loanStatusL.setId(id);
loanStatusL.setStatus("1");
//调用更改借阅状态的service方法
this.loan_management.changLoanStatus(loanStatusL);
return "redirect:/admin/loan/outStanding.action";
}
}
return "admin/loan_bespeak";
}
//列表查询
@RequestMapping("/loan/searchBespeak")
public String searchBespeak(Model model, String searchSelect, String searchKeyWord, Integer currentPage) throws Exception {
TbOrderL tbOrderL = new TbOrderL();
//如果传入的有页面
if (currentPage != null) {
tbOrderL.setCurrentPage(currentPage);
}
//实例化包装类(包装类中在原有类的基础上添加的column(列名称)和keyword(搜索关键字)两个字段)
tbOrderL.setColumn(searchSelect);
tbOrderL.setKeyWord(searchKeyWord);
pageL pageL = new pageL();
pageL = this.loan_management.getBespeakRecord(tbOrderL);
List<TbOrderL> BespeakList = (List<TbOrderL>) pageL.getPo();
model.addAttribute("pageL", pageL);
model.addAttribute("BespeakList", BespeakList);
return "admin/loan_bespeak";
}
// 领取操作
@RequestMapping("/loan/getBespeak")
public String getBespeak(Model model, Integer id, Integer bookid, Integer userid) throws Exception {
//通过bookid和userid 借阅表插入借阅记录
TbRecord tbRecord = new TbRecord();
tbRecord.setBookId(bookid);
tbRecord.setUserId(userid);
this.loan_management.addLoanList(tbRecord);
//通过id删除预约记录
this.loan_management.removeOrderList(id);
//返回借阅列表
return "redirect:/admin/loan/bespeakList.action";
}
// 删除预约记录
@RequestMapping("/loan/removeBespeak")
public String removeBespeak(Integer id) throws Exception {
this.loan_management.removeOrderList(id);
return "redirect:/admin/loan/bespeakList.action";
}