作者主页:源码空间站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.数据库:MySql 5.7、8.0等版本均可;
6.是否Maven项目:否;
技术栈
JSP+CSS+JavaScript+servlet+mysql
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应sql文件名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,配置tomcat;
3. 将项目中bean/DBO.java配置文件中的数据库配置改为自己的配置;
4. 运行项目,在浏览器中输入http://localhost:8080/jsp_zaixianbook_shop/ 登录
管理员账号/密码:admin/admin
用户账号/密码: user/123456
运行截图
设计文稿
前台界面-用户角色
前台页面
相关代码
图书管理控制层
@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;
}
}
订单管理控制器
@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<OrderForm> orderFormList = iOrderFormService.findAllOrderForm(num,size);
PageInfo<OrderForm> orderFormPageInfo = new PageInfo<>(orderFormList);
model.addAttribute("orderFormPageInfo",orderFormPageInfo);
return "/backstage/order_form";
}
/**
* 获取所有用户订单返回JSON数据
* @return
*/
@GetMapping("/findAllOrderForm1")
public @ResponseBody PageInfo<OrderForm> findAllOrderForm1(
@RequestParam(defaultValue = "1") Integer num,
@RequestParam(defaultValue = "5") Integer size
) {
List<OrderForm> orderFormList = iOrderFormService.findAllOrderForm(num,size);
PageInfo<OrderForm> 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<OrderForm> orderFormList = iOrderFormService.findByUid(uid,num,size);
PageInfo<OrderForm> 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;
}
}
购物车管理控制器
@Controller
@RequestMapping("/shopping")
public class ShoppingController {
@Autowired
private IShoppingService iShoppingService;
@Autowired
private IOrderFormService iOrderFormService;
/**
* 添加购物车或修改购物车已有图书商品
*
* @param sp
* @return
*/
@PostMapping("/saveShopping")
public @ResponseBody
int saveShopping(Shopping sp) {
// System.out.println("获取到的值:"+shopping);
int i = iShoppingService.saveShopping(sp);
// System.out.println("返回i="+i);
return i;
}
/**
* 我的购物车
*
* @param uid
* @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<Shopping> shoppingList = iShoppingService.findByUid(uid,num,size);
PageInfo<Shopping> shoppingPageInfo = new PageInfo<>(shoppingList);
model.addAttribute("shoppingPageInfo", shoppingPageInfo);
return "/frontdesk/shopping";
}
/**
* 移除购物车某一图书商品
*
* @param id
* @return
*/
@PostMapping("/deleteShopping/{uid}/{id}")
public @ResponseBody
int findByUid(@PathVariable Integer uid, @PathVariable Integer id) {
int i = iShoppingService.deleteShopping(uid, id);
// System.out.println("返回的i="+i);
return i;
}
/**
* 购买某一图书商品
* 1、新增订单
* 2、移除购物车某一图书商品
*
* @param id
* @return
*/
@PostMapping("/detShoppingSaveOrderForm")
@Transactional
public @ResponseBody
int detShoppingSaveOrderForm(Integer id) {
// 新增订单
Shopping shopping = iShoppingService.findById(id);
OrderForm orderForm = shoppingOrderForm(shopping);
int i1 = iOrderFormService.saveOrderForm(orderForm);
// 移除购物车某一图书商品
int i = iShoppingService.deleteShopping(shopping.getUid(), shopping.getId());
// System.out.println("返回的i="+i);
int count = i + i1;
return count;
}
/**
* 将购物车图书信息转化封装到订单实体类中
*
* @param shopping
* @return
*/
public static OrderForm shoppingOrderForm(Shopping shopping) {
OrderForm orderForm = new OrderForm();
orderForm.setImage(shopping.getImage());
orderForm.setName(shopping.getName());
orderForm.setPprice(shopping.getPprice());
orderForm.setBcount(shopping.getBcount());
orderForm.setBid(shopping.getBid());
orderForm.setUid(shopping.getUid());
return orderForm;
}
}
如果也想学习本系统,下面领取。关注并回复:077jsp