基于javaweb的在线电子商城管理系统(java+springboot+thymeleaf+bootstrap+jq+layui+mysql)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+SpringBoot的在线电子商城管理系统(java+SpringBoot+Thymeleaf+bootstrap+jQ+layui+maven+mysql)
项目介绍
本项目分为管理员与普通用户两种角色, 管理员角色包含以下功能: 发货,后台登录后首页,商品管理,商城类别增删改查,用户管理,管理员登录,订单管理,资料截图,首页等功能。 用户角色包含以下功能:
查看分类,加入购物车,提交订单,查看商品详情,查看订单,用户登录等功能。
环境需要
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版本;
6.是否Maven项目:是;
技术栈
-
后端:SpringBoot+Thymeleaf
-
前端:HTML+CSS+JavaScript+bootstrap+jQuery+layui
使用说明
-
使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
-
使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
- 将项目中application.properties配置文件中的数据库配置改为自己的配置; 4. 运行项目,在浏览器中输入http://localhost:8082/mall/ 登录 普通用户账号密码: me/123456
管理员账号密码: admin/admin
前台-订单列表控制层:
@Controller
public class ForeOrderController extends BaseController {
@Autowired
private ProductService productService;
@Autowired
private UserService userService;
@Autowired
private ProductOrderItemService productOrderItemService;
@Autowired
private AddressService addressService;
@Autowired
private CategoryService categoryService;
@Autowired
private ProductImageService productImageService;
@Autowired
private ProductOrderService productOrderService;
@Autowired
private ReviewService reviewService;
@Autowired
private LastIDService lastIDService;
//转到前台-订单列表页
@RequestMapping(value = “order”, method = RequestMethod.GET)
public String goToPageSimple() {
return “redirect:/order/0/10”;
@RequestMapping(value = “order/{index}/{count}”, method = RequestMethod.GET)
public String goToPage(HttpSession session, Map<String, Object> map,
@RequestParam(required = false) Byte status,
@PathVariable(“index”) Integer index/* 页数 */,
@PathVariable(“count”) Integer count/* 行数*/) {
logger.info(“检查用户是否登录”);
Object userId = checkUser(session);
User user;
if (userId != null) {
logger.info(“获取用户信息”);
user = userService.get(Integer.parseInt(userId.toString()));
map.put(“user”, user);
} else {
return “redirect:/login”;
Byte[] status_array = null;
if (status != null) {
status_array = new Byte[]{status};
PageUtil pageUtil = new PageUtil(index, count);
logger.info(“根据用户ID:{}获取订单列表”, userId);
List productOrderList = productOrderService.getList(new ProductOrder().setProductOrder_user(new User().setUser_id(Integer.valueOf(userId.toString()))), status_array, new OrderUtil(“productOrder_id”, true), pageUtil);
//订单总数量
Integer orderCount = 0;
if (productOrderList.size() > 0) {
orderCount = productOrderService.getTotal(new ProductOrder().setProductOrder_user(new User().setUser_id(Integer.valueOf(userId.toString()))), status_array);
logger.info(“获取订单项信息及对应的产品信息”);
for (ProductOrder order : productOrderList) {
List productOrderItemList = productOrderItemService.getListByOrderId(order.getProductOrder_id(), null);
if (productOrderItemList != null) {
for (ProductOrderItem productOrderItem : productOrderItemList) {
Integer product_id = productOrderItem.getProductOrderItem_product().getProduct_id();
Product product = productService.get(product_id);
product.setSingleProductImageList(productImageService.getList(product_id, (byte) 0, new PageUtil(0, 1)));
productOrderItem.setProductOrderItem_product(product);
if (order.getProductOrder_status() == 3) {
productOrderItem.setIsReview(reviewService.getTotalByOrderItemId(productOrderItem.getProductOrderItem_id()) > 0);
order.setProductOrderItemList(productOrderItemList);
pageUtil.setTotal(orderCount);
logger.info(“获取产品分类列表信息”);
List categoryList = categoryService.getList(null, new PageUtil(0, 5));
map.put(“pageUtil”, pageUtil);
map.put(“productOrderList”, productOrderList);
map.put(“categoryList”, categoryList);
map.put(“status”, status);
logger.info(“转到前台天猫-订单列表页”);
return “fore/orderListPage”;
//转到前台天猫-订单建立页
@RequestMapping(value = “order/create/{product_id}”, method = RequestMethod.GET)
public String goToOrderConfirmPage(@PathVariable(“product_id”) Integer product_id,
@RequestParam(required = false, defaultValue = “1”) Short product_number,
Map<String, Object> map,
HttpSession session,
HttpServletRequest request) throws UnsupportedEncodingException {
logger.info(“检查用户是否登录”);
Object userId = checkUser(session);
User user;
if (userId != null) {
logger.info(“获取用户信息”);
user = userService.get(Integer.parseInt(userId.toString()));
map.put(“user”, user);
} else {
return “redirect:/login”;
logger.info(“通过产品ID获取产品信息:{}”, product_id);
Product product = productService.get(product_id);
if (product == null) {
return “redirect:/”;
logger.info(“获取产品的详细信息”);
product.setProduct_category(categoryService.get(product.getProduct_category().getCategory_id()));
product.setSingleProductImageList(productImageService.getList(product_id, (byte) 0, new PageUtil(0, 1)));
logger.info(“封装订单项对象”);
ProductOrderItem productOrderItem = new ProductOrderItem();
productOrderItem.setProductOrderItem_product(product);
productOrderItem.setProductOrderItem_number(product_number);
productOrderItem.setProductOrderItem_price(product.getProduct_sale_price() * product_number);
productOrderItem.setProductOrderItem_user(new User().setUser_id(Integer.valueOf(userId.toString())));
String addressId = “110000”;
String cityAddressId = “110100”;
String districtAddressId = “110101”;
String detailsAddress = null;
String order_post = null;
String order_receiver = null;
String order_phone = null;
Cookie[] cookies = request.getCookies();
if (cookies != null) {
for (Cookie cookie : cookies) {
String cookieName = cookie.getName();
String cookieValue = cookie.getValue();
switch (cookieName) {
case “addressId”:
addressId = cookieValue;
break;
case “cityAddressId”:
cityAddressId = cookieValue;
break;
case “districtAddressId”:
districtAddressId = cookieValue;
break;
case “order_post”:
order_post = URLDecoder.decode(cookieValue, “UTF-8”);
break;
case “order_receiver”:
order_receiver = URLDecoder.decode(cookieValue, “UTF-8”);
break;
case “order_phone”:
order_phone = URLDecoder.decode(cookieValue, “UTF-8”);
break;
case “detailsAddress”:
detailsAddress = URLDecoder.decode(cookieValue, “UTF-8”);
break;
logger.info(“获取省份信息”);
List
addressList = addressService.getRoot();logger.info(“获取addressId为{}的市级地址信息”, addressId);
List
cityAddress = addressService.getList(null, addressId);logger.info(“获取cityAddressId为{}的区级地址信息”, cityAddressId);
List
districtAddress = addressService.getList(null, cityAddressId);List productOrderItemList = new ArrayList<>();
productOrderItemList.add(productOrderItem);
map.put(“orderItemList”, productOrderItemList);
map.put(“addressList”, addressList);
map.put(“cityList”, cityAddress);
map.put(“districtList”, districtAddress);
map.put(“orderTotalPrice”, productOrderItem.getProductOrderItem_price());
map.put(“addressId”, addressId);
map.put(“cityAddressId”, cityAddressId);
map.put(“districtAddressId”, districtAddressId);
map.put(“order_post”, order_post);
map.put(“order_receiver”, order_receiver);
map.put(“order_phone”, order_phone);
map.put(“detailsAddress”, detailsAddress);
logger.info(“转到前台天猫-订单建立页”);
return “fore/productBuyPage”;
//转到前台天猫-购物车订单建立页
@RequestMapping(value = “order/create/byCart”, method = RequestMethod.GET)
public String goToOrderConfirmPageByCart(Map<String, Object> map,
HttpSession session, HttpServletRequest request,
@RequestParam(required = false) Integer[] order_item_list) throws UnsupportedEncodingException {
logger.info(“检查用户是否登录”);
Object userId = checkUser(session);
User user;
if (userId != null) {
logger.info(“获取用户信息”);
user = userService.get(Integer.parseInt(userId.toString()));
map.put(“user”, user);
} else {
return “redirect:/login”;
if (order_item_list == null || order_item_list.length == 0) {
logger.warn(“用户订单项数组不存在,回到购物车页”);
return “redirect:/cart”;
logger.info(“通过订单项ID数组获取订单信息”);
List orderItemList = new ArrayList<>(order_item_list.length);
for (Integer orderItem_id : order_item_list) {
orderItemList.add(productOrderItemService.get(orderItem_id));
logger.info(“------检查订单项合法性------”);
if (orderItemList.size() == 0) {
logger.warn(“用户订单项获取失败,回到购物车页”);
return “redirect:/cart”;
for (ProductOrderItem orderItem : orderItemList) {
if (orderItem.getProductOrderItem_user().getUser_id() != userId) {
logger.warn(“用户订单项与用户不匹配,回到购物车页”);
return “redirect:/cart”;
if (orderItem.getProductOrderItem_order() != null) {
logger.warn(“用户订单项不属于购物车,回到购物车页”);
return “redirect:/cart”;
logger.info(“验证通过,获取订单项的产品信息”);
double orderTotalPrice = 0.0;
for (ProductOrderItem orderItem : orderItemList) {
Product product = productService.get(orderItem.getProductOrderItem_product().getProduct_id());
product.setProduct_category(categoryService.get(product