作者主页:夜未央5788
简介: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

- 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
bookTypeList = iBookTypeService.findAllBookType(1,100 ); - model.addAttribute("bookTypeList", bookTypeList);
- // 获取供应商
- List
supplierList = iSupplierService.findAllSupplier(1,100); - model.addAttribute("supplierList", supplierList);
- // 获取图书
- List
booksList = iBookService.findAllBook(num,size); - PageInfo
booksPageInfo = new PageInfo<>(booksList); - model.addAttribute("booksPageInfo", booksPageInfo);
- return "/backstage/home";
- }
-
- /**
- * 图书列表
- * @param model
- * @return
- */
- @GetMapping("/home1")
- public @ResponseBody PageInfo
toAdminHome1( - @RequestParam(defaultValue = "1") Integer num,
- @RequestParam(defaultValue = "5")Integer size,
- Model model
- ) {
- // 获取导航栏
- List
bookTypeList = iBookTypeService.findAllBookType(1,100); - model.addAttribute("bookTypeList", bookTypeList);
- // 获取供应商
- List
supplierList = iSupplierService.findAllSupplier(1,100 ); - model.addAttribute("supplierList", supplierList);
- // 获取图书
- List
booksList = iBookService.findAllBook(num,size); - PageInfo
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
bookTypeList = iBookTypeService.findAllBookType(1,100); - model.addAttribute("bookTypeList", bookTypeList);
- // 获取全部图书
- List
booksList = iBookService.findAllBook(num,size ); - PageInfo
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
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
booksList = iBookService.findByTid(tid,num,size); - PageInfo
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;
- }
- }
- package com.hk.controller;
-
- import com.github.pagehelper.PageInfo;
- import com.hk.model.BookType;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.Model;
- import org.springframework.web.bind.annotation.*;
- import com.hk.service.IBookTypeService;
-
- import java.util.List;
-
- /**
- * @author zhe
- * @Create 2021/5/27/23:26
- * @State 图书类型(导航)
- */
- @Controller
- @RequestMapping("/bookType")
- public class BookTypeController {
-
- @Autowired
- private IBookTypeService iBookTypeService;
-
- /**
- * 查询所有图书类型
- */
- @GetMapping("/findAllBookType")
- public String findAllBookType(
- @RequestParam(defaultValue = "1") Integer num,
- @RequestParam(defaultValue = "5")Integer size,
- Model model
- ) {
- List
bookTypeList = iBookTypeService.findAllBookType(num,size); - PageInfo
bookTypePageInfo = new PageInfo<>(bookTypeList); - model.addAttribute("bookTypePageInfo",bookTypePageInfo);
- return "/backstage/book_type";
- }
-
- /**
- * 返回JSON
- * 查询所有图书类型
- */
- @GetMapping("/findAllBookType1")
- public @ResponseBody PageInfo
findAllBookType1( - @RequestParam(defaultValue = "1") Integer num,
- @RequestParam(defaultValue = "5")Integer size
- ) {
- List
bookTypeList = iBookTypeService.findAllBookType(num,size); - PageInfo
bookTypePageInfo = new PageInfo<>(bookTypeList); - return bookTypePageInfo;
- }
-
- /**
- * 新增图书类型
- * @param bookType
- * @return
- */
- @PostMapping("/saveBookType")
- public String saveBookType(BookType bookType) {
- iBookTypeService.saveBookType(bookType);
- return "redirect:/bookType/findAllBookType";
- }
-
- /**
- * 查询单独图书类型
- * @param id
- * @return
- */
- @PostMapping("/findById/{id}")
- public @ResponseBody BookType findById(@PathVariable Integer id) {
- BookType bookType = iBookTypeService.findById(id);
- return bookType;
- }
-
- /**
- * 修改图书类型
- * @param bookType
- * @return
- */
- @PostMapping("/updateBookType")
- public @ResponseBody int updateBookType(BookType bookType) {
- // System.out.println("bookType:"+bookType);
- int i = iBookTypeService.updateBookType(bookType);
- return i;
- }
-
- /**
- * 根据Id删除
- * @param id
- * @return
- */
- @PostMapping("/deleteBookType/{id}")
- public @ResponseBody int deleteBookType (@PathVariable Integer id) {
- int i = iBookTypeService.deleteBookType(id);
- return i;
- }
- }
- package com.hk.controller;
-
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.RequestMapping;
-
- /**
- * @author zhe
- * @Create 2021/5/27/23:45
- * @State 页面入口
- */
- @Controller
- public class MainController {
-
- @RequestMapping("/admin")
- public String admin() {
- return "redirect:/users/adminLogin";
- }
-
- @RequestMapping("/")
- public String qiantai() {
- return "redirect:/book/qiantai";
- }
-
- }
- package com.hk.controller;
-
- import com.github.pagehelper.PageInfo;
- import com.hk.model.OrderForm;
- import com.hk.service.IOrderFormService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.Model;
- import org.springframework.web.bind.annotation.*;
-
- import java.util.List;
-
- /**
- * @author zhe
- * @Create 2021/5/29/19:13
- * @State 订单管理
- */
- @Controller
- @RequestMapping("/orderForm")
- public class OrderFormController {
-
- @Autowired
- private IOrderFormService iOrderFormService;
-
- /**
- * 获取所有用户订单
- * @param model
- * @return
- */
- @GetMapping("/findAllOrderForm")
- public String findAllOrderForm(
- @RequestParam(defaultValue = "1") Integer num,
- @RequestParam(defaultValue = "5") Integer size,
- Model model) {
- List
orderFormList = iOrderFormService.findAllOrderForm(num,size); - PageInfo
orderFormPageInfo = new PageInfo<>(orderFormList); - model.addAttribute("orderFormPageInfo",orderFormPageInfo);
- return "/backstage/order_form";
- }
-
- /**
- * 获取所有用户订单返回JSON数据
- * @return
- */
- @GetMapping("/findAllOrderForm1")
- public @ResponseBody PageInfo
findAllOrderForm1( - @RequestParam(defaultValue = "1") Integer num,
- @RequestParam(defaultValue = "5") Integer size
- ) {
- List
orderFormList = iOrderFormService.findAllOrderForm(num,size); - PageInfo
orderFormPageInfo = new PageInfo<>(orderFormList); - return orderFormPageInfo;
- }
-
- /**
- * 新增订单
- * 1、将商品销售增加
- * 2、剩余量减少
- * 3、产生订单
- * @param orderForm
- * @return
- */
- @PostMapping("/saveOrderForm")
- public @ResponseBody int saveOrderForm(OrderForm orderForm) {
- // System.out.println("OrderForm:"+orderForm);
- int i = iOrderFormService.saveOrderForm(orderForm);
- return i;
- }
-
- /**
- * 搜索指定用户的订单列表
- * @param uid
- * @param num
- * @param size
- * @param model
- * @return
- */
- @GetMapping("/findByUid/{uid}")
- public String findByUid(
- @PathVariable Integer uid,
- @RequestParam(defaultValue = "1") Integer num,
- @RequestParam(defaultValue = "5") Integer size,
- Model model) {
- List
orderFormList = iOrderFormService.findByUid(uid,num,size); - PageInfo
orderFormPageInfo = new PageInfo<>(orderFormList); - model.addAttribute("orderFormPageInfo",orderFormPageInfo);
- return "/frontdesk/order_form";
- }
-
- /**
- * 是否发货
- * @param orderForm
- * @return
- */
- @PostMapping("/updateOrderForm")
- public @ResponseBody int updateOrderForm(OrderForm orderForm) {
- int i = iOrderFormService.updateOrderForm(orderForm);
- return i;
- }
-
- /**
- * 移除该用户的某一订单
- * @param id
- * @return
- */
- @PostMapping("/deleteShopping/{uid}/{id}")
- public @ResponseBody int findByUid(@PathVariable Integer uid,@PathVariable Integer id) {
- int i = iOrderFormService.deleteOrderForm(uid,id);
- // System.out.println("返回的i="+i);
- return i;
- }
-
- /**
- * 根据主键Id删除某一订单
- * @return
- */
- @PostMapping("/deleteDeliver/{id}")
- public @ResponseBody int deleteDeliver(@PathVariable Integer id) {
- int i = iOrderFormService.deleteDeliver(id);
- return i;
- }
- }
如果也想学习本系统,下面领取。关注并回复:064ssm