"基于JSP的购物商城(SQLServer版)
1.包含源程序,数据库脚本。代码和数据库脚本都有详细注释。
2.课题设计仅供参考学习使用,可以在此基础上进行扩展完善。有需要源码可以找我一起讨论
代码已经上传github,下载地址https://github.com/21503882/net-shop
开发环境:
Eclipse ,SQLServer 2005,JDK1.7,Tomcat 7
涉及技术点:
MVC模式、JavaWeb、JDBC、HTML、CSS、JQUERY、文件上传、购物车等
程序功能:
1.网站前台:
用户注册登录、找回密码、新闻公告、留言板、联系我们、商品购买、购物车、我的订单、订单评价等。
2.后台管理:
管理员登录、修改密码、新闻公告管理、商品类别管理、商品管理、仓储管理、订单管理、销量统计、账单管理、会员管理、留言管理、管理员管理等。"
package com.renttravel.controller;
import com.renttravel.FormEntity.CarListForm;
import com.renttravel.entity.EspecialGoodsEntity;
import com.renttravel.entity.GoodsCarEntity;
import com.renttravel.interceptor.SysLog;
import com.renttravel.service.EspecialGoodsService;
import com.renttravel.service.GoodsCarService;
import com.renttravel.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.*;
/**
* 购物车逻辑
* created by nicking
* data: 2019/2/28
* time: 15:51
*/
@RestController
@RequestMapping("/api")
public class GoodsCarController {
@Autowired
private GoodsCarService goodsCarService;
@Autowired
private EspecialGoodsService especialGoodsService;
@SysLog("添加商品购物车")
@RequestMapping(value = "/goods/add/car", method = RequestMethod.GET)
public R addToCar(GoodsCarEntity entity) {
Map
map.put("user_id", entity.getUserId());
map.put("goods_id", entity.getGoodsId());
List
if (null != list && list.size() > 0) {
GoodsCarEntity goodsCarEntity = new GoodsCarEntity();
goodsCarEntity.setId(list.get(0).getId());
goodsCarEntity.setCreateTime(new Date());
goodsCarEntity.setGoodsId(entity.getGoodsId());
goodsCarEntity.setUserId(entity.getUserId());
goodsCarEntity.setNum(list.get(0).getNum() + 1);
goodsCarService.updateById(goodsCarEntity);
} else {
entity.setNum(1);
goodsCarService.insert(entity);
}
return R.ok();
}
@SysLog("减少购物车商品数量")
@RequestMapping(value = "/goods/reduce/car", method = RequestMethod.GET)
public R reduceToCar(GoodsCarEntity entity) {
if (entity.getNum() == 0) {
goodsCarService.deleteById(entity.getId());
} else {
goodsCarService.updateById(entity);
}
return R.ok();
}
@SysLog("删除购物车商品")
@RequestMapping(value = "/goods/delete/car", method = RequestMethod.GET)
public R deleteFromCar(GoodsCarEntity entity) {
goodsCarService.deleteById(entity.getId());
return R.ok();
}
/**
* 获取购物车列表
* @param userId 当前登录用户
* @return 返回购物车列表
*/
@RequestMapping(value = "/goods/car/list", method = RequestMethod.GET)
public R getCarList(int userId) {
List
Map
map.put("user_id", userId);
List
for (GoodsCarEntity entity : carList) {
EspecialGoodsEntity especialGoodsEntity = especialGoodsService.selectById(entity.getGoodsId());
CarListForm carListForm = new CarListForm();
carListForm.setNum(entity.getNum());
carListForm.setId(entity.getId());
carListForm.setGoodsId(entity.getGoodsId());
carListForm.setContent(especialGoodsEntity.getContent());
carListForm.setTitle(especialGoodsEntity.getTitle());
carListForm.setImgUrl(especialGoodsEntity.getImgUrl());
carListForm.setRealPrice(especialGoodsEntity.getRealPrice());
resultList.add(carListForm);
}
return R.ok().put("data", resultList);
}
}
package com.renttravel.controller;
import com.renttravel.FormEntity.FinishOrder;
import com.renttravel.FormEntity.OrderForm;
import com.renttravel.entity.EspecialGoodsEntity;
import com.renttravel.entity.OrderEntity;
import com.renttravel.service.EspecialGoodsService;
import com.renttravel.service.GoodsCarService;
import com.renttravel.service.OrderService;
import com.renttravel.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 下订单
* created by nicking
* data: 2019/3/3
* time: 17:43
*/
@RestController
@RequestMapping("/api")
public class OrderController {
@Autowired
private OrderService orderService;
@Autowired
private GoodsCarService goodsCarService;
@Autowired
private EspecialGoodsService especialGoodsService;
/**
* 下单
*/
@RequestMapping(value = "/buy/goods", method = RequestMethod.POST)
public R doOrder(@RequestBody List
if (entList.size()>0) {
for (OrderForm orderForm : entList) {
OrderEntity orderEntity = new OrderEntity();
orderEntity.setCountNum(orderForm.getCount());
orderEntity.setGoodsId(orderForm.getGoodsId());
orderEntity.setUserId(orderForm.getUserId());
orderEntity.setTotalPrice(orderForm.getCount()*orderForm.getPrice());
orderService.insert(orderEntity);
goodsCarService.deleteById(orderForm.getCarId());
}
} else {
return R.error("还没有选择商品哦");
}
return R.ok();
}
/**
* 获取完成的订单列表
*/
@RequestMapping(value = "/order/finish/list", method = RequestMethod.GET)
public R finishOrderList(long userId) {
List
Map
map.put("user_id", userId);
List
for (OrderEntity itemList : list) {
FinishOrder finishOrder = new FinishOrder();
EspecialGoodsEntity especialGoodsEntity = especialGoodsService.selectById(itemList.getGoodsId());
finishOrder.setId(itemList.getId());
finishOrder.setCount(itemList.getCountNum());
finishOrder.setPrice(itemList.getTotalPrice());
finishOrder.setTitle(especialGoodsEntity.getTitle());
finishOrder.setImgUrl(especialGoodsEntity.getImgUrl());
finishOrder.setGoodsId(especialGoodsEntity.getId());
resultList.add(finishOrder);
}
return R.ok().put("data", resultList);
}
}
代码已经上传github,下载地址https://github.com/21503882/net-shop
————————————————