1、项目介绍
基于SSM图书管理系统、书籍管理系统,系统功能有:
1).登录:用户进入登录界面,输入账号密码登录系统,如果账号密码正确,就会,就会成功进入系统,反之会提示账号或密码错误;
2).查询:在查询功能模块输入图书的相关信息,搜索图书,馆藏有要找的图书就会显示图书信息;
3).添加:有新购、捐赠等书籍入库就要用到此功能模块,将新来的图书的基本信息录入系统;
4).删除:删除淘汰的书籍,损坏、丢失不在馆内的书籍要在系统中将她们删除掉,清算正确的在架的图书数量;
5).修改:修改图书的基本信息,如作者、书名等,以确保在查询的时候不会出现错误的信息,误导读者。
2、技术架构
编程语言:Java
系统架构:B/S
后端框架:SSM
前端框架:JSP+layui
数据库:MySQL
Maven项目:是
服务器:Tomcat
运行环境:JDK8+Idea+Mysql5.6+Maven3.5+Tomcat8.5
3、演示视频
B站地址:
基于SSM图书管理系统、书籍管理系统,附源码+文档报告+数据库,适合课程设计、大作业 、大实验、实训
基于SSM图书管理系统、书籍管理系统,附源码+文档报告+数据库,适合课程设计、大作业 、大实验、实训_哔哩哔哩_bilibili
4、功能截图
4.1、登录
4.2、所有图书
4.3、查询图书
4.3、上架新书
4.4、最新图书列表
4.5、下架图书列表
5、文档截图
6、代码示例
package cn.test.bookms.controller;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import cn.test.bookms.entity.MsAdmin;
import cn.test.bookms.service.MsAdminService;
import cn.test.bookms.util.Message;
@Controller
public class LoginController {
@Autowired
private MsAdminService msAdminService;
@RequestMapping(value = "/login")
public String toLogin() {
return "login";
}
@RequestMapping(value = "/adminLogin")
public String adminLogin(String adminNumber,String adminPwd,HttpSession httpSession,HttpSession httpSession2) {
Map map = new HashMap();
map.put("adminNumber", adminNumber);
map.put("adminPwd", adminPwd);
MsAdmin msAdmin = msAdminService.selectAdmin(map);
if(msAdmin != null) {
httpSession.setAttribute("msAdmin", msAdmin);
//httpSession.setMaxInactiveInterval(1800); //默认存在半个小时 设置回话存在时长 秒单位
httpSession.setAttribute("imgPath", Message.IMG_PATH);
return "index";
}else {
httpSession2.setAttribute("Login_error", Message.LOGIN_FAILED_MSG);
httpSession2.setMaxInactiveInterval(1); //设置该消息存在一秒,显示后下次访问页面即消失
return "redirect:/login";
}
}
/**
* 安全退出
* @param httpSession
* @return
*/
@RequestMapping(value = "/adminLogout")
public String adminLogout(HttpSession httpSession) {
MsAdmin msAdmin = (MsAdmin) httpSession.getAttribute("msAdmin"); //从sesion中获取MsAdmin对象
if(msAdmin !=null) {
httpSession.removeAttribute("msAdmin"); //移除
return "redirect:/login"; //重定向到登登录界面
}
return "redirect:/login";
}
}
package cn.test.bookms.controller;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import cn.test.bookms.entity.MsAdmin;
import cn.test.bookms.entity.MsBook;
import cn.test.bookms.entity.MsCategory;
import cn.test.bookms.service.MsBookService;
import cn.test.bookms.service.MsCategoryService;
import cn.test.bookms.util.Message;
@Controller
public class BookController {
@Autowired
private MsBookService msBookService;
@Autowired
private MsCategoryService msCategoryService;
@RequestMapping(value = "/showBook")
public String showAllBookByPage(@RequestParam(value="currentPage",defaultValue="1",required=false)
int currentPage,String title,String author,Model model) {
model.addAttribute("pageMsg",msBookService.selectByPage(title, author, currentPage));
return "showAllBook";
}
/******************查询图书***********************
*
*/
//跳转页面
@RequestMapping(value = "/searchBook")
public String toSearchBook() {
return "searchBook";
}
@RequestMapping(value = "/searchBookPage")
public String searchBook(@RequestParam(value="currentPage",defaultValue="1",required=false)
int currentPage,String title,String author,Model model) {
model.addAttribute("pageMsg",msBookService.selectByPage(title, author, currentPage));
return "searchBook";
}
/**
* ****************查询图书end*********************
*/
/**
* 查看图书详细信息
*/
@RequestMapping(value="/bookDetail")
public String showBookDetail(int id,Model model) {
MsBook book = msBookService.selectByID(id);
MsCategory cate = msCategoryService.selectByPrimaryKey(book.getCategoryId());
model.addAttribute("book",book);
model.addAttribute("cate", cate);
return "bookDetail";
}
/**
* 跳转到添加图书页面
* @return
*/
@RequestMapping(value = "/toAddNewBook")
public String toAddNewBook() {
return "addNewBook";
}
/**
* 添加图书
* @param book
* @param file
* @param request
* @return
*/
@RequestMapping(value="/addNewBook")
public String addNewBook(MsBook book,MultipartFile file,HttpServletRequest request,HttpSession httpSession) {
MsAdmin admin = (MsAdmin)httpSession.getAttribute("msAdmin");
System.out.println("页面提交过来的表单:"+book);
//SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
book.setCreateTime(new Date());
book.setCreateAdmin(admin.getAdminName());
book.setUpdatePreAdmin(admin.getAdminName());
book.setDelFlg(1);
String filePath = request.getSession().getServletContext().getRealPath("/bookImage");; //定义图片上传后的路径
System.out.println("文件上传路径:"+filePath);
// String newFileName = fileOperate(file,Message.IMG_LOCAL_PATH);
String newFileName = fileOperate(file,filePath);
book.setImage(newFileName);
System.out.println("添加数据后的book:"+book);
msBookService.insertBook(book);
return "redirect:newBookList";
}
/**
* 查询最近上架的图书
*/
@RequestMapping(value="/newBookList")
public String newBookList(Model model) {
model.addAttribute("newBookList", msBookService.selectNewBook());
return "newBookList";
}
/**
* 下架图书
* @param id
* @return
*/
@RequestMapping(value = "/deleteBook")
public String deleteBook(int id) {
msBookService.deleteByPrimaryKey(id);
return "redirect:showBook";
}
/**
* 下架新上架的图书
* @param id
* @return
*/
@RequestMapping(value = "/deleteBookNewList")
public String deleteBookNewList(int id) {
msBookService.deleteByPrimaryKey(id);
return "redirect:newBookList";
}
/**
* 下架查询到的图书
* @param id
* @return
*/
@RequestMapping(value = "/deleteSearchBook")
public String deleteSearchBook(int id) {
msBookService.deleteByPrimaryKey(id);
return "redirect:searchBook";
}
/**
* 已下架图书列表
*/
@RequestMapping(value = "/deleteBookList")
public String deleteBookList(Model model) {
model.addAttribute("bookList", msBookService.selectBookDel());
return "delBookList";
}
/**
* 跳转到修改书籍信息
*/
@RequestMapping(value = "/toUpdateBook")
public String updateBookPage(int id,Model model) {
MsBook book = msBookService.selectByID(id);
MsCategory cate = msCategoryService.selectByPrimaryKey(book.getCategoryId());
model.addAttribute("book", book);
model.addAttribute("cate", cate);
return "editBook";
}
/**
* 修改图书信息
* @param book
* @param file
* @param httpSession
* @return
*/
@RequestMapping(value = "/updateBook")
public String updateBook(MsBook book,MultipartFile file,HttpSession httpSession,HttpServletRequest request) {
System.out.println("上传过来的图书信息:"+book);
MsBook oldBook = msBookService.selectByID(book.getId());
book.setPublishTime(oldBook.getPublishTime());
MsAdmin admin = (MsAdmin)httpSession.getAttribute("msAdmin");
book.setUpdatePreAdmin(admin.getAdminName());
String filePath = request.getSession().getServletContext().getRealPath("/bookImage");; //定义图片上传后的路径
// String newFileName = fileOperate(file,Message.IMG_LOCAL_PATH);
String newFileName = fileOperate(file,filePath);
book.setImage(newFileName);
System.out.println("添加完成的图书信息:"+book);
msBookService.updateByPrimaryKeySelective(book);
return "redirect:showBook";
}
/**
* 重新上架图书
*/
@RequestMapping("/updateBackBook")
public String updateBackBook(int id) {
msBookService.updateBackBook(id);
return "redirect:deleteBookList";
}
/**
* 彻底删除图书
*/
@RequestMapping("/deleteBookReal")
public String deleteBookReal(int id) {
msBookService.deleteBookReal(id);
return "redirect:deleteBookList";
}
/**
* 封装操作文件方法,
* @param file
* @param filePath
* @return
*/
private String fileOperate(MultipartFile file,String filePath) {
System.out.println("进入文件操作方法");
String originalFileName = file.getOriginalFilename();//获取原始图片的扩展名
System.out.println("图片原始名称:"+originalFileName);
String newFileName = UUID.randomUUID()+originalFileName; //新的文件名称
System.out.println("新的文件名称:"+newFileName);
File targetFile = new File(filePath,newFileName); //创建新文件
try {
file.transferTo(targetFile); //把本地文件上传到文件位置 , transferTo()是springmvc封装的方法,用于图片上传时,把内存中图片写入磁盘
System.out.println("文件上传成功!");
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return newFileName;
}
}