基于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 +等等。
tbLibraryQuery.setCateId(0);
}
PageCount<TblibraryExt> libraryPageCount = libraryService.findLibraryByAll(tbLibraryQuery, pageCount);
model.addAttribute("libraryPageCount", libraryPageCount);
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";
}
}
// 判断该 图书是否是 父类目
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);
}
}
/**
* @description: 图书服务实现类
*
*/
@Service
public class LibraryServiceImpl implements LibraryService {
// 注入
@Autowired
private TbLibraryAndManagerMapper libraryAndManagerMapper;
@Autowired
private TbLibraryMapper libraryMapper;
@Controller
public class IframeController {
@Autowired
private LibraryCategoryService libraryCategoryService;
@Autowired
private LibraryService libraryService;
@RequestMapping("/admin/{adminPage}")
public String admin(@PathVariable String adminPage, HttpSession session) throws Exception {
if (session.getAttribute("categoryAll") == null) {
// 图书类目 ,设置到 session 中
List<TbCategory> categoryAll = libraryCategoryService.getCategoryAll();
session.setAttribute("categoryAll", categoryAll);
}
return "admin/" + adminPage;
}
@RequestMapping("/user/{userPage}")
public String user(@PathVariable String userPage, HttpSession session, Model model) throws Exception {
// 获取图书类目信息
List<TbCategory> categoryAll = libraryCategoryService.getCategoryAll();
session.setAttribute("userCategoryAll", categoryAll);
//
TbLibraryQuery libraryQuery = new TbLibraryQuery();
libraryQuery.setCateId(0);
libraryQuery.setBookname("");
// 將图书 設置到 域中
PageCount<TblibraryExt> libraryPageCount = libraryService.findLibraryByAll(libraryQuery, null);
// 查询所有 类目 父 id 为 0 的
List<TbCategory> subCategoryList = libraryCategoryService.getCategoryByParentId(0);
model.addAttribute("libraryPageCount", libraryPageCount);
model.addAttribute("subCategoryList", subCategoryList);
session.setAttribute("currentCategory", 0);
return "user/" + userPage;
}
@RequestMapping("/{loginPage}")
public String index(@PathVariable String loginPage) throws Exception {
return loginPage;
}
@Override
public void updateUserOne(TbUser tbUser, MultipartFile uploadFile, HttpServletRequest request) throws Exception {
String headImg = UploadFileUtilsByUser.updateLibrary(uploadFile, request,USERIMG_FILE_SAVE_PATH);
System.out.println(headImg);
tbUser.setHeadimg(headImg);
this.tbUserMapperL.updateUserOne(tbUser);
}
}
/**
* @description: 列表页面显示
*/
@Controller
@RequestMapping("/admin/ch")
public class PageController {
// 注入
@Autowired
private LibraryService libraryService;
@Autowired
private LibraryCategoryService libraryCategoryService;
/**
* 查询图书列表
*
* @param model
* @param tbLibraryQuery
* @param pageCount
* @return
*/
@RequestMapping(value = "/loan_bookList", method = RequestMethod.GET)
public String showBookListPage(Model model, TbLibraryQuery tbLibraryQuery, PageCount pageCount) {
// 判断数据有效性
if (tbLibraryQuery != null) {
msg = "手机号不能为空!";
url = "/login.action";
model.addAttribute("msg", msg);
model.addAttribute("url", url);
}
//判断验证码是否错误
if (!validateCode.equals(authcode)) {
msg = "您输入的验证码错误!";
url = "/login.action";
model.addAttribute("msg", msg);
model.addAttribute("url", url);
return "user/error";
}
//如果都正确,注册用户
tbUser.setUsername(user);
tbUser.setPassword(pwd);
tbUser.setTelnum(tel);
long nowTime = System.currentTimeMillis() / 1000;
tbUser.setRegisterdate(nowTime);
int result = this.login_loginValidation.addUser(tbUser);
//判断是否注册成功
if (0 == result) {
msg = "注册失败,用户名已存在!";
url = "/login.action";
model.addAttribute("msg", msg);
model.addAttribute("url", url);
return "user/error";
}
//注册成功,将用户名放入seesion中
tbUser = this.login_loginValidation.findUserByUserName(user);
activeUser.setUserid(tbUser.getId());
activeUser.setUsername(tbUser.getUsername());
activeUser.setHeadImg(tbUser.getHeadimg());
session.setAttribute("activeUser", activeUser);
msg = "注册成功!正在为您登录,请稍候...";
url = "/user/userSystem.action";
model.addAttribute("msg", msg);
model.addAttribute("url", url);
return "user/error";
} else {
msg = "参数错误!";
url = "/login.action";
order.setDeadline(currentTimeS + 3 * 30 * 24 * 60 * 60); //预约 3个月天 时间
orderMapper.insert(order);
}
}
/**
* @desc 登录注册Controller
**/
@Controller
@RequestMapping("/login")
public class Login_LoginController {
@Autowired
private Login_loginValidation login_loginValidation;
@RequestMapping("/login")
public String login(Model model, HttpSession session, String user, String pwd, String passwd2, String tel, String authcode, String statu) throws Exception {
//提示信息
String msg;
//跳转页面
String url;
//登录
ActiveUser activeUser = new ActiveUser();
TbUser tbUser = new TbUser();
if ("1".equals(statu)) {
activeUser = this.login_loginValidation.authenticat(user, pwd);
if (activeUser == null) {
for (TbRecordQueryVo vo : recordOverdueList) {
if (vo.getTicketffee() < 0) {
model.addAttribute("errorMsg", "该学生有欠款不可以借阅");
return "errorMsg";
}
}
TbRecord record = new TbRecord();
// 获取 session 中的用户信息
record.setUserId(tbUser.getId());
record.setBookId(book.getId());
Long currentTimeS = System.currentTimeMillis() / 1000;
record.setRecorddate(currentTimeS); //预约 借阅时间
record.setBackdate(currentTimeS + 3 * 30 * 24 * 60 * 60); //预约 3个月天 时间
record.setTicketffee(0f);
record.setReturnbook(0);
// 插入数据
recordMapper.insert(record);
model.addAttribute("successMsg", "借阅成功");
return "errorMsg";
}
//借阅列表显示
@RequestMapping("/loan/loanList")
public String loanList(Model model, Integer currentPage) throws Exception {
TbRecordL tbRecordL = new TbRecordL();
//如果传入的有页面
if (currentPage != null) {
tbRecordL.setCurrentPage(currentPage);
}
//查询数据和分页,并返回
pageL pageL = this.loan_management.getLoanRecord(tbRecordL);
List<TbRecordL> loanRecordList = (List<TbRecordL>) pageL.getPo();
model.addAttribute("pageL", pageL);
model.addAttribute("loanRecordList", loanRecordList);
return "admin/loan_loanList";
}
//借阅列表搜素
@RequestMapping("/loan/searchLoanList.action")
public String searchLoanList(Model model, String searchSelect, String searchKeyWord) throws Exception {
System.out.println(headImg);
tbUser.setHeadimg(headImg);
this.tbUserMapperL.updateUserOne(tbUser);
}
}
/**
* @description: 列表页面显示
*/
@Controller
@RequestMapping("/admin/ch")
public class PageController {
// 注入
@Autowired
private LibraryService libraryService;
@Autowired
private LibraryCategoryService libraryCategoryService;
/**
* 查询图书列表
*
* @param model
* @param tbLibraryQuery
* @param pageCount
* @return
*/
@RequestMapping(value = "/loan_bookList", method = RequestMethod.GET)
public String showBookListPage(Model model, TbLibraryQuery tbLibraryQuery, PageCount pageCount) {
// 判断数据有效性
if (tbLibraryQuery != null) {
tbLibraryQuery.setCateId(0);
public String toLibraryListByCid(TbLibraryQuery libraryQuery, PageCount pageCount, Model model, HttpSession session) {
if (libraryQuery == null || libraryQuery.getCateId() == null) {
libraryQuery = new TbLibraryQuery();
libraryQuery.setCateId((Integer) session.getAttribute("currentCategory"));
}
// 根据 类目 id
// 若 当前 类目 为 父类目 则获取 其 下面 的 所有子类目
// 若 当前 类目 为 子类目 则获取 其 同级 类目
List<TbCategory> categoryList = libraryCategoryService.getCategoryByCid(libraryQuery.getCateId());
// 获取当前类目信息
TbCategory currentCategory = libraryCategoryService.getCategoryById(libraryQuery.getCateId());
// 按照条件进行查询
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);
PageCount<TblibraryExt> libraryPageCount = libraryService.findLibraryByAll(tbLibraryQuery, pageCount);
model.addAttribute("libraryPageCount", libraryPageCount);
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";
}
}
tbUserQueryVo.setOnline(online);
List<TbUser> userList = loan_userInfoList.selectLikeName(tbUserQueryVo);
model.addAttribute("userList", userList);
return "admin/loan_userList";
}
}
/**
* @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);
if (library.getId() != null) {
// 修改图书信息,修改 不为空的
libraryMapper.updateByPrimaryKeySelective(library);
} else {
library.setCreatedate(System.currentTimeMillis() / 1000);
library.setPublishdate(System.currentTimeMillis() / 1000);
libraryMapper.insert(library);
}
return fileSavePath;
}
@Override
public void delBookById(int id) {
// 删除 订单表
TbOrderExample orderExample = new TbOrderExample();
orderExample.createCriteria().andBookIdEqualTo(id);
orderMapper.deleteByExample(orderExample);
// 删除 预约表
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);
// 判断图书的有效性
tbUser.setRegisterdate(System.currentTimeMillis());
//not online
tbUser.setIsonline(0);
tbUser.setPassword(tbUser.getUsername());
int i = loan_userInfoList.addUser(tbUser);
if (i > 0) {
System.out.println("添加成功!");
return "redirect:loan_userList.action";
}
return "redirect:loan_userList.action";
}
//用户列表模糊查询用户信息(用户名)
@RequestMapping("/loan_selectLikeName")
public String Loan_selectLikeName(TbUser tbUser, Model model) {
Integer online = null;
TbUserQueryVo tbUserQueryVo = new TbUserQueryVo();
tbUserQueryVo.setTbUser(tbUser);
tbUserQueryVo.setOnline(online);
List<TbUser> userList = loan_userInfoList.selectLikeName(tbUserQueryVo);
model.addAttribute("userList", userList);
return "admin/loan_userList";
}
}
/**
* @desc 借出未还
**/
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";
}*/
}
/**
* 图书借阅管理Controller
*
**/
@Controller
@RequestMapping("/admin")
public class Loan_LoanListController {
@Override
public PageCount<TblibraryExt> findLibraryByAll(TbLibraryQuery tbLibraryQuery, PageCount pageCount) {
// 判断 分页数据的 有效性
if (tbLibraryQuery == null) {
tbLibraryQuery = new TbLibraryQuery();
tbLibraryQuery.setBookname("");
}
if (pageCount == null) {
pageCount = new PageCount();
pageCount.setCurrentPage(Integer.parseInt(CURRENT_PAGE));
pageCount.setPageRows(Integer.parseInt(PAGE_ROWS));
}
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<TblibraryExt> tblibraryExts = new ArrayList<>();
// 判断是否为 0
if (tbLibraryQuery.getCateId() == 0) {
// 获取图书列表
tblibraryExts = libraryAndManagerMapper.findAll(tbLibraryQuery);
} else {
// 获取图书列表
tblibraryExts = libraryAndManagerMapper.findLibraryByCriteria(tbLibraryQuery);
}
// 获取 页数,查询记录数 的详细信息
PageInfo<TblibraryExt> pageInfo = new PageInfo<>(tblibraryExts);
pageCount.setTotalPages(pageInfo.getPages());
pageCount.setTotalRows(pageInfo.getTotal());
pageCount.setContentList(tblibraryExts);
return pageCount;
}
@Override
public TbLibrary findLibraryByBid(int id) {
// 通过 主键id 查询图书信息
return libraryMapper.selectByPrimaryKey(id);
}
parentCategory.setIsParent(false);
// 更新数据
categoryMapper.updateByPrimaryKeySelective(parentCategory);
}
}
@Override
public void updateBookCategoryById(TbCategory category) {
categoryMapper.updateByPrimaryKeySelective(category);
}
@Override
public TbCategory getCategoryById(int id) {
return categoryMapper.selectByPrimaryKey(id);
}
@Override
public List<TbCategory> getCategoryByParentId(int parentId) {
// 创建 查询对象
TbCategoryExample categoryExample = new TbCategoryExample();
// 添加查询条件
categoryExample.createCriteria().andParentIdEqualTo(parentId);
List<TbCategory> subCategoryList = categoryMapper.selectByExample(categoryExample);
if (subCategoryList == null || subCategoryList.size() < 1) {
return null;
}
return subCategoryList;
}
@Override
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);
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";
}
}
/**
* @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";
} else {
// 获取图书列表
tblibraryExts = libraryAndManagerMapper.findLibraryByCriteria(tbLibraryQuery);
}
// 获取 页数,查询记录数 的详细信息
PageInfo<TblibraryExt> pageInfo = new PageInfo<>(tblibraryExts);
pageCount.setTotalPages(pageInfo.getPages());
pageCount.setTotalRows(pageInfo.getTotal());
pageCount.setContentList(tblibraryExts);
return pageCount;
}
@Override
public TbLibrary findLibraryByBid(int id) {
// 通过 主键id 查询图书信息
return libraryMapper.selectByPrimaryKey(id);
}
@Override
public String updateOrSaveLibrary(MultipartFile uploadFile, TbLibrary library, HttpServletRequest request) throws IOException {
// 上传文件保存 路径
String FILE_SAVE_PATH=request.getSession().getServletContext().getRealPath("/upload/book");;
String fileSavePath = UploadFileUtilsByBook.updateLibrary(uploadFile, FILE_SAVE_PATH);
// 修改 图书信息
library.setImg(fileSavePath);
// 对图书操作进行判断.若 有id 则 进行 修改操作,否则 添加 操作
if (library.getId() != null) {
// 修改图书信息,修改 不为空的
libraryMapper.updateByPrimaryKeySelective(library);
} else {
library.setCreatedate(System.currentTimeMillis() / 1000);
library.setPublishdate(System.currentTimeMillis() / 1000);
libraryMapper.insert(library);
}
return fileSavePath;
}
@Override
public void delBookById(int id) {
// 删除 订单表
TbOrderExample orderExample = new TbOrderExample();