Java项目:阿博图书馆管理系统(java+SpringBoot+Mybaits+Vue+elementui+mysql)

 源码获取:俺的博客首页 "资源" 里下载!

项目介绍

基于Springboot+vue阿博图书馆管理系统

环境需要

1.运行环境:最好是java jdk 1.8 其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
4.数据库:MySql 5.7/8.0版本均可;
5.是否Maven项目:是;


技术栈

后端:SpringBoot+Mybaits

前端:Vue + elementui


使用说明

项目运行:
1. 使用Navicat或者其它工具,在mysql中创建对应sql文件名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,导入成功后请执行maven clean;maven install命令;
3. 将项目中application.yml配置文件中的数据库配置改为自己的配置;
4. 运行项目,在浏览器中输入地址:
前台地址:http://localhost:8080/springboot33dng/front/index.html

后台地址
http://localhost:8080/springboot33dng/admin/dist/index.html
管理员 abo 密码 abo
用户:用户1 密码: 123456

注意项目文件路径中不能含有中文、空格、特殊字符等,否则图片会上传不成功。

 

 

图书管理类控制层:

/**
 * 图书管理类
 */
@Controller
@RequestMapping("/web/books")
public class BookController extends BaseController{
	
	
	@Autowired
	private IBookService bookService;
	@Autowired
	private IBorrowBookService borrowBookService;

	/**
	 * 默认索引页
	 * @parameter 参数及其意义
	 * @return index页面
	 */
	@RequestMapping("/index")
	public String index() {
		return "/admin/books/index";
	}
	/**
	 * 添加图书
	 * @parameter 
	 * @return addform页面
	 */
	@RequestMapping(value = {"/addBook"}, method = RequestMethod.GET)
	public String addBook() {
		return "admin/books/addform";
	}
	
	/**
	 * 删除图书
	 * @parameter 图书id,数据集
	 * @return JsonResult 是否成功
	 */
	
	@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
	@ResponseBody
	public JsonResult delete(@PathVariable String id,ModelMap map) {
		try {
			bookService.delete(id);
		} catch (Exception e) {
			e.printStackTrace();
			return JsonResult.failure(e.getMessage());
		}
		return JsonResult.success();
	}
	
	/**
	 * 借书
	 * @parameter Json类型的借书表,数据集
	 * @return JsonResult
	 */
	@RequestMapping(value = { "/borrowlist/{borrowlist}" },method = RequestMethod.POST)
	@ResponseBody
	public JsonResult borrowList(@PathVariable String borrowlist,ModelMap map) {
		
		if(!borrowlist.equals("undefine"))
		{
			Gson gson=new Gson();
			BorrowList mBorrowList=gson.fromJson(borrowlist,BorrowList.class);
			BorrowBook[] borrowBook=new BorrowBook[mBorrowList.getBooklist().length];
			Book[] book=new Book[mBorrowList.getBooklist().length];
			int i=0;
			while(i<mBorrowList.getBooklist().length)
			{
				borrowBook[i]=new BorrowBook();
				book[i]=new Book();
				borrowBook[i].setUserId(mBorrowList.getId());
				borrowBook[i].setBookId(mBorrowList.getBooklist()[i]);
				book[i]=bookService.findByBookId(mBorrowList.getBooklist()[i]);
				//一本书只能借一次,因此需要判断一下该用户是否已经借过该书
				BorrowBook isBorrowBook=borrowBookService.findByUserIdAndBookId(mBorrowList.getId(), mBorrowList.getBooklist()[i]);
				if(book[i].getCurrentInventory()>0)
				{
					if(isBorrowBook==null)
					{
						book[i].setCurrentInventory(book[i].getCurrentInventory()-1);
						bookService.saveOrUpdate(book[i]);
						borrowBookService.save(borrowBook[i]);
					}else
					{
						return JsonResult.failure("您已经借阅该书!");
					}
					
				}else
				{
					return JsonResult.failure("库存不足请重新选择图书!");
				}
				
				i++;
			}
			i=0;
			
			return JsonResult.success();
		}else
		{
			return JsonResult.failure("未选择要借阅的书籍!");
		}
		
		
	}
	
	/**
	 * 还书表
	 * @parameter 借书用户id
	 * @return String 借书表信息和书籍信息
	 */
	@RequestMapping(value = { "/returnBookList/{id}" },method = RequestMethod.POST)
	@ResponseBody
	public String ReturnBookList(@PathVariable String id,ModelMap map) {
		
		BorrowBook[] borrowBooks=borrowBookService.findByUserId(Integer.parseInt(id));
		Book[] books=new Book[borrowBooks.length];
		Date date=null;
		for(int i=0;i<books.length;i++)
		{
			books[i]=bookService.findByBookId(borrowBooks[i].getBookId());			
		}
		Map<String,Object> resultMap=new HashMap();
		resultMap.put("borrowBooks", borrowBooks);
		resultMap.put("books", books);
		Gson gson=new Gson();
		String jsonStr = gson.toJson(resultMap);	
		
		return jsonStr;
	}
	
	/**
	 * 归还图书
	 * @parameter Json类型的借书表
	 * @return JsonResult
	 */
	@RequestMapping(value = {"/returnBook/{borrowlist}"}, method = RequestMethod.POST)
	@ResponseBody
	public JsonResult returnBook(@PathVariable String borrowlist) {

		Gson gson=new Gson();
		BorrowList mBorrowList=gson.fromJson(borrowlist,BorrowList.class);
		BorrowBook[] borrowBook=new BorrowBook[mBorrowList.getBooklist().length];
		Book[] book=new Book[mBorrowList.getBooklist().length];
		int i=0;
		while(i<mBorrowList.getBooklist().length)
		{
			borrowBook[i]=new BorrowBook();
			book[i]=new Book();
			borrowBook[i].setUserId(mBorrowList.getId());
			borrowBook[i].setBookId(mBorrowList.getBooklist()[i]);
			book[i]=bookService.findByBookId(mBorrowList.getBooklist()[i]);
			book[i].setCurrentInventory(book[i].getCurrentInventory()+1);
			bookService.saveOrUpdate(book[i]);
			borrowBookService.deletByUserIdAndBookId(borrowBook[i].getUserId(), borrowBook[i].getBookId());;
			i++;
		}
		i=0;
		return JsonResult.success();
	}
	
	/**
	 * 修改图书响应请求
	 * @parameter 修改的图书id,数据集
	 * @return String addform页面
	 */
	@RequestMapping(value = "/edit/{id}", method = RequestMethod.GET)
	public String edit(@PathVariable String id,ModelMap map) {
		
		Book book = bookService.findByBookId(id);
		map.put("book", book);
		return "admin/books/addform";
	}
	
	/**
	 * 修改图书
	 * @parameter 图书实体,数据集
	 * @return JsonResult 是否修改成功
	 */
	
	@RequestMapping(value= {"/edit"} ,method = RequestMethod.POST)
	@ResponseBody
	public JsonResult edit( Book book,ModelMap map){
		try {
			bookService.saveOrUpdate(book);
		} catch (Exception e) {
			return JsonResult.failure(e.getMessage());
		}
		return JsonResult.success();
	}

	
	/**
	 * index页面中BootStrapTable请求列表响应
	 * @parameter 
	 * @return Page<Book>
	 */
	@RequestMapping(value = { "/list" })
	@ResponseBody
	public Page<Book> list() {
		
		SimpleSpecificationBuilder<Book> builder = new SimpleSpecificationBuilder<Book>();
		String searchText = request.getParameter("searchText");
		if(StringUtils.isNotBlank(searchText)){
			builder.add("bookName", Operator.likeAll.name(), searchText);
		}
		Page<Book> page = bookService.findAll(builder.generateSpecification(), getPageRequest());
		return page;
	}
	
	/**
	 * 查询图书
	 * @parameter 
	 * @return Page<Book>
	 */
	@RequestMapping(value = { "/findlist" })
	@ResponseBody
	public Page<Book> findList() {
		
		SimpleSpecificationBuilder<Book> builder = new SimpleSpecificationBuilder<Book>();
		String bookName = request.getParameter("inputBookName");
		String bookAuthor = request.getParameter("inputAuthor");
		String bookPress = request.getParameter("inputPublication");		
		if(StringUtils.isNotBlank(bookName)){
			builder.add("bookName", Operator.likeAll.name(), bookName);
		}
		if(StringUtils.isNotBlank(bookAuthor)){
			builder.add("bookAuthor", Operator.likeAll.name(), bookAuthor);
		
		}
		if(StringUtils.isNotBlank(bookPress)){
			builder.add("bookPress", Operator.likeAll.name(), bookPress);
		}
		Page<Book> page = bookService.findAll(builder.generateSpecification(), getPageRequest());
		return page;
	}
	
	
	
	
}

用户管理控制层:

@Controller
@RequestMapping("/admin/user")
public class UserController extends BaseController {

	@Autowired
	private IUserService userService;
	@Autowired
	private IRoleService roleService;

	@RequestMapping(value = { "/", "/index" })
	public String index() {
		return "admin/user/index";
	}

	@RequestMapping(value = { "/list" })
	@ResponseBody
	public Page<User> list() {
		SimpleSpecificationBuilder<User> builder = new SimpleSpecificationBuilder<User>();
		String searchText = request.getParameter("searchText");
		if(StringUtils.isNotBlank(searchText)){
			builder.add("nickName", Operator.likeAll.name(), searchText);
		}
		
		Page<User> page = userService.findAll(builder.generateSpecification(), getPageRequest());
		return page;
	}
	
	@RequestMapping(value = "/add", method = RequestMethod.GET)
	public String add(ModelMap map) {
		return "admin/user/form";
	}

	@RequestMapping(value = "/edit/{id}", method = RequestMethod.GET)
	public String edit(@PathVariable Integer id,ModelMap map) {
		User user = userService.find(id);
		map.put("user", user);
		return "admin/user/form";
	}
	
	@RequestMapping(value= {"/edit"} ,method = RequestMethod.POST)
	@ResponseBody
	public JsonResult edit(User user,ModelMap map){
		try {
			System.out.println("inputuser:"+user.toString());
			userService.saveOrUpdate(user);
		} catch (Exception e) {
			return JsonResult.failure(e.getMessage());
		}
		return JsonResult.success();
	}
	
	@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
	@ResponseBody
	public JsonResult delete(@PathVariable Integer id,ModelMap map) {
		try {
			userService.delete(id);
		} catch (Exception e) {
			e.printStackTrace();
			return JsonResult.failure(e.getMessage());
		}
		return JsonResult.success();
	}
	
	@RequestMapping(value = "/grant/{id}", method = RequestMethod.GET)
	public String grant(@PathVariable Integer id, ModelMap map) {
		User user = userService.find(id);
		map.put("user", user);
		
		Set<Role> set = user.getRoles();
		List<Integer> roleIds = new ArrayList<Integer>();
		for (Role role : set) {
			roleIds.add(role.getId());
		}
		map.put("roleIds", roleIds);
		
		List<Role> roles = roleService.findAll();
		map.put("roles", roles);
		return "admin/user/grant";
	}
	
	@ResponseBody
	@RequestMapping(value = "/grant/{id}", method = RequestMethod.POST)
	public JsonResult grant(@PathVariable Integer id,String[] roleIds, ModelMap map) {
		try {
			userService.grant(id,roleIds);
		} catch (Exception e) {
			e.printStackTrace();
			return JsonResult.failure(e.getMessage());
		}
		return JsonResult.success();
	}
}

资源管理控制层:

@Controller
@RequestMapping("/admin/resource")
public class ResourceController extends BaseController {
	@Autowired
	private IResourceService resourceService;
	
	@RequestMapping("/tree/{resourceId}")
	@ResponseBody
	public List<ZtreeView> tree(@PathVariable Integer resourceId){
		List<ZtreeView> list = resourceService.tree(resourceId);
		return list;
	}
	
	@RequestMapping("/index")
	public String index() {
		return "admin/resource/index";
	}

	@RequestMapping("/list")
	@ResponseBody
	public Page<Resource> list() {
		SimpleSpecificationBuilder<Resource> builder = new SimpleSpecificationBuilder<Resource>();
		String searchText = request.getParameter("searchText");
		if(StringUtils.isNotBlank(searchText)){
			builder.add("name", Operator.likeAll.name(), searchText);
		}
		Page<Resource> page = resourceService.findAll(builder.generateSpecification(),getPageRequest());
		return page;
	}
	
	@RequestMapping(value = "/add", method = RequestMethod.GET)
	public String add(ModelMap map) {
		List<Resource> list = resourceService.findAll();
		map.put("list", list);
		return "admin/resource/form";
	}
	

	@RequestMapping(value = "/edit/{id}", method = RequestMethod.GET)
	public String edit(@PathVariable Integer id,ModelMap map) {
		Resource resource = resourceService.find(id);
		map.put("resource", resource);
		
		List<Resource> list = resourceService.findAll();
		map.put("list", list);
		return "admin/resource/form";
	}
	
	@RequestMapping(value= {"/edit"}, method = RequestMethod.POST)
	@ResponseBody
	public JsonResult edit(Resource resource,ModelMap map){
		try {
			resourceService.saveOrUpdate(resource);
		} catch (Exception e) {
			return JsonResult.failure(e.getMessage());
		}
		return JsonResult.success();
	}
	
	@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
	@ResponseBody
	public JsonResult delete(@PathVariable Integer id,ModelMap map) {
		try {
			resourceService.delete(id);
		} catch (Exception e) {
			e.printStackTrace();
			return JsonResult.failure(e.getMessage());
		}
		return JsonResult.success();
	}
}

源码获取:俺的博客首页 "资源" 里下载!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

OldWinePot

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值