作者主页:源码空间站2022
简介:Java领域优质创作者、Java项目、学习资料、技术互助
文末获取源码
项目介绍
该项目分为前后台,前台主要功能包括:
普通用户的注册、登录;
轮播图展示、图书列表、图书详情、加入购物车、我的订单等功能;
后台主要功能包括:
图书管理:图书列表、图书类型、供应商列表-包括图书、类型、供应商等的新增、修改、删除;
订单管理:订单列表-订单发货、删除;
用户管理:用户列表-用户新增、修改、删除;
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.是否Maven项目: 是;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目
6.数据库:MySql 8.0版本;
技术栈
1. 后端:Spring SpringMVC MyBatis
2. 前端:JSP+bootstrap+jQuery+layui
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,配置tomcat;
3. 将项目中applicationContext.xml配置文件中的数据库配置改为自己的配置;
4. 前台:http://localhost:8080/book/qiantai
后台:http://localhost:8080/admin
运行截图
相关代码
BookController
package com.hk.controller;
import com.github.pagehelper.PageInfo;
import com.hk.model.BookType;
import com.hk.model.Books;
import com.hk.model.Supplier;
import com.hk.service.IBookService;
import com.hk.service.IBookTypeService;
import com.hk.service.ISupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
/**
* @author zhe
* @Create 2021/5/27/23:11
* @State 图书管理控制层
*/
@Controller
@RequestMapping("/book")
@SessionAttributes({"bookTypeList"})
public class BookController {
@Autowired
private IBookTypeService iBookTypeService;
@Autowired
private IBookService iBookService;
@Autowired
private ISupplierService iSupplierService;
/**
* 图书列表
* @param model
* @return
*/
@GetMapping("/home")
public String toAdminHome(
@RequestParam(defaultValue = "1") Integer num,
@RequestParam(defaultValue = "5")Integer size,
Model model
) {
// 获取导航栏
List<BookType> bookTypeList = iBookTypeService.findAllBookType(1,100 );
model.addAttribute("bookTypeList", bookTypeList);
// 获取供应商
List<Supplier> supplierList = iSupplierService.findAllSupplier(1,100);
model.addAttribute("supplierList", supplierList);
// 获取图书
List<Books> booksList = iBookService.findAllBook(num,size);
PageInfo<Books> booksPageInfo = new PageInfo<>(booksList);
model.addAttribute("booksPageInfo", booksPageInfo);
return "/backstage/home";
}
/**
* 图书列表
* @param model
* @return
*/
@GetMapping("/home1")
public @ResponseBody PageInfo<Books> toAdminHome1(
@RequestParam(defaultValue = "1") Integer num,
@RequestParam(defaultValue = "5")Integer size,
Model model
) {
// 获取导航栏
List<BookType> bookTypeList = iBookTypeService.findAllBookType(1,100);
model.addAttribute("bookTypeList", bookTypeList);
// 获取供应商
List<Supplier> supplierList = iSupplierService.findAllSupplier(1,100 );
model.addAttribute("supplierList", supplierList);
// 获取图书
List<Books> booksList = iBookService.findAllBook(num,size);
PageInfo<Books> booksPageInfo = new PageInfo<>(booksList);
return booksPageInfo;
}
/**
* 上传图书图片
* @param request
* @param file
* @return
*/
@PostMapping("/uploadimg")
public @ResponseBody int uploadimg(HttpServletRequest request, MultipartFile file) {
int i = iBookService.uploadImage(request,file);
return i;
}
/**
* 上传详情图片
* @param request
* @param file
* @return
*/
@PostMapping("/uploaddetail")
public @ResponseBody int uploaddetail(HttpServletRequest request, MultipartFile file) {
int i = iBookService.uploaddetail(request,file);
return i;
}
/**
*新增图书
* @return
*/
@PostMapping("/saveBook")
public String saveBook(Books books) {
// System.out.println("Books:="+books);
iBookService.saveBook(books);
return "redirect:/book/home";
}
/**
* 前台首页
*
* @return
*/
@GetMapping("/qiantai")
public String toHome(
@RequestParam(defaultValue = "1") Integer num,
@RequestParam(defaultValue = "10")Integer size,
Model model) {
// 获取导航栏
List<BookType> bookTypeList = iBookTypeService.findAllBookType(1,100);
model.addAttribute("bookTypeList", bookTypeList);
// 获取全部图书
List<Books> booksList = iBookService.findAllBook(num,size );
PageInfo<Books> booksPageInfo = new PageInfo<>(booksList);
model.addAttribute("booksPageInfo", booksPageInfo);
return "/frontdesk/home";
}
/**
* 通过Id查询图书详情
* @param id
* @param model
* @return
*/
@GetMapping("/findById/{id}")
public String findById(@PathVariable Integer id,Model model) {
Books books = iBookService.findById(id);
model.addAttribute("books",books);
return "/frontdesk/book_detail";
}
/**
* 管理员通过Id查询图书详情
* @param id
* @param model
* @return
*/
@GetMapping("/adminfindById/{id}")
public String adminfindById(@PathVariable Integer id,Model model) {
// 获取供应商
List<Supplier> supplierList = iSupplierService.findAllSupplier(1,100 );
model.addAttribute("supplierList", supplierList);
// 获取图书详情
Books books = iBookService.findById(id);
model.addAttribute("books",books);
return "/backstage/update_book";
}
/**
* 修改图书信息
* @param books
* @return
*/
@PostMapping("/updateBook")
public String updateBook(Books books) {
// System.out.println("返回的图书:"+books);
iBookService.updateBook(books);
return "redirect:/book/home";
}
/**
* 通过图书类型Id查询图书
* @param tid
* @param model
* @return
*/
@GetMapping("/findByTid/{tid}")
public String findByTid(@PathVariable Integer tid,@RequestParam(defaultValue = "1") Integer num,@RequestParam(defaultValue = "10")Integer size,Model model) {
List<Books> booksList = iBookService.findByTid(tid,num,size);
PageInfo<Books> booksPageInfo = new PageInfo<>(booksList);
model.addAttribute("booksPageInfo", booksPageInfo);
model.addAttribute("tid",tid);
return "/frontdesk/home";
}
@PostMapping("/deleteBook/{id}")
public @ResponseBody int deleteBook(@PathVariable("id") Integer id) {
int i = iBookService.deleteBook(id);
return i;
}
}
如果也想学习本系统,下面领取。关注并回复:064ssm