基于javaweb+mysql的springboot网上电商项目(前后端分离+java+vue+springboot+ssm+mysql+maven+redis)
运行环境
Java≥8、MySQL≥5.7、Node.js≥10
开发工具
后端:eclipse/idea/myeclipse/sts等均可配置运行
前端:WebStorm/VSCode/HBuilderX等均可
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot网上电商项目(前后端分离+java+vue+springboot+ssm+mysql+maven+redis)
一、项目简述
本系统功能包括: 一款基于Springboot+Vue的电商项目,前后端分离项目,前台后台都有,前台商品展示购买,购物车分类,订 单查询等等,后台商品管理,订单管理,信息维护,用户管理等等。
二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + Mysql + HBuilderX (Webstorm也 行)+ Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts都支 持)。
项目技术: Springboot + Maven + Mybatis + Vue + Redis, B/S 模式+ Maven等等,附带支付宝沙箱环境以及支付环节代码。
/**
* 退出登录操作
* @param key 用户登录的帐号
* @param session 前端存储的session(token)
*/
@RequestMapping(value = "/logout")
private CommonResult logout(String key,String session) {
if(key!=null){
try{
User user = userService.selectByKey(key);
Subject subject = SecurityUtils.getSubject();
//清除用户缓存
RealmSecurityManager securityManager = (RealmSecurityManager) SecurityUtils.getSecurityManager();
UserRealm userRealm = (UserRealm) securityManager.getRealms().iterator().next();
//清空redis中的缓存信息
userRealm.clearRedis(user,session);
userRealm.clearCache(SecurityUtils.getSubject().getPrincipals());
//退出登录
subject.logout();
return CommonResult.success("退出成功");
}catch(Exception e){
logger.error(e.getMessage());
}
}
return CommonResult.error("退出失败,未找到用户帐号");
}
//权限不够时,将转到此请求上来
@RequestMapping("/notRole")
private CommonResult notRole(){
return new CommonResult(403,"暂无权限!");
}
/*判断key是否存在 目前用于判断邮箱是否被注册过*/
@RequestMapping(value = "/allow/existUser")
private CommonResult existUser(String accountNumber) {
Boolean isExist = userService.existsWithPrimaryKey(accountNumber);
if(isExist!=null){
return CommonResult.success("查询成功",isExist);
}else{
return CommonResult.error("查询失败");
}
}
/*判断手机号phone是否存在 目前被用于绑定手机号时,确认手机号已被绑定*/
@RequestMapping(value = "/allow/existPhone")
private CommonResult existPhone(String telephone) {
Boolean isExist = userService.existsWithPrimaryPhone(telephone);
if(isExist!=null){
}else{
return CommonResult.error("商品轮播图查询失败");
}
}
}
@CrossOrigin
@Controller
public class OssController {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final AliyunOssUtil ossUtil;
public OssController(AliyunOssUtil ossUtil) {
this.ossUtil = ossUtil;
}
@RequestMapping("/uploadImage")
@ResponseBody
public CommonResult upload(@RequestParam("name") String folderName, @RequestParam("file") MultipartFile file) {
String path = null;
try {
if (file != null) {
String fileName = file.getOriginalFilename();
if (fileName!=null && !fileName.isEmpty()) {
File newFile = new File(fileName);
FileOutputStream os = new FileOutputStream(newFile);
os.write(file.getBytes());
os.close();
//把file里的内容复制到奥newFile中
file.transferTo(newFile);
//图片回显地址:
path = ossUtil.upload(folderName,newFile);
logger.info("path=" + path);
}
}
} catch (Exception e) {
e.printStackTrace();
}
/*返回json 数据*/
CommonResult commonResult;
if (path != null){
commonResult = new CommonResult(200,"上传成功",path);
}else{
}else{
return CommonResult.error("商品分类删除失败");
}
}
@RequestMapping(value = "/productType/existsTypeName")
private CommonResult existsTypeName(Integer typeId,String typeName) {
Boolean isExist = productTypeService.existsWithTypeName(typeId,typeName);
if(isExist!=null){
return CommonResult.success("查询成功",isExist);
}else{
return CommonResult.error("查询失败");
}
}
@RequestMapping(value = "/productType/findAll")
private CommonResult findAllType() {
List<ProductType> productTypes = productTypeService.selectAll();
if(productTypes!=null){
return CommonResult.success("商品分类查询成功",productTypes);
}else{
return CommonResult.error("商品分类查询失败");
}
}
@RequestMapping(value = "/productType/findAllName")
private CommonResult findAllTypeName() {
List<String> names = productTypeService.selectAllName();
if(names!=null){
return CommonResult.success("商品分类名称查询成功",names);
}else{
return CommonResult.error("商品分类名称查询失败");
}
}
/*商品品牌*/
@RequestMapping(value = "/productBrand/add")
private CommonResult addBrand(ProductBrand productBrand) {
if(productBrandService.insertData(productBrand)){
return CommonResult.success("商品品牌添加成功",productBrand);
}else{
return CommonResult.error("商品品牌添加失败");
}
}
@RequestMapping(value = "/productBrand/update")
private CommonResult updateBrand(ProductBrand productBrand) {
if(productBrandService.updateById(productBrand)){
return CommonResult.success("商品品牌修改成功",productBrand);
public class SpecsController {
final SpecsService specsService;
final ProductSpecsService productSpecsService;
public SpecsController(SpecsService specsService,ProductSpecsService productSpecsService) {
this.specsService = specsService;
this.productSpecsService = productSpecsService;
}
/*根据id查询规格*/
@RequestMapping(value = "/specs/findById")
private CommonResult findById(Integer specsId) {
Specs specs = specsService.selectById(specsId);
if(specs!=null){
return CommonResult.success("查询成功",specs);
}else{
return CommonResult.error("查询失败");
}
}
/*查询所有规格信息*/
@RequestMapping(value = "/specs/findAll")
private CommonResult findAllSpecs() {
List<Specs> specs = specsService.selectAll();
if(specs!=null){
return CommonResult.success("查询成功",specs);
}else{
return CommonResult.error("查询失败");
}
}
@RequestMapping(value = "/specs/existsSpecsName")
private CommonResult existsSpecsName(Integer specsId, String specsName, String productType) {
Boolean isExist = specsService.existsWithSpecsName(specsId,specsName,productType);
if(isExist!=null){
return CommonResult.success("查询成功",isExist);
}else{
return CommonResult.error("查询失败");
}
}
@RequestMapping(value = "/specs/findAllByType")
private CommonResult findAllSpecsByType(String productType) {
List<Specs> specs = specsService.selectAllByType(productType);
if(specs!=null){
return CommonResult.success("查询成功",specs);
}else{
return CommonResult.success("查询成功",user);
}else{
return CommonResult.error("查询失败");
}
}
/*查询所有用户*/
@RequestMapping(value = "/user/findAll")
private CommonResult findAll() {
List<User> users = userService.selectAll();
if(users!=null){
return CommonResult.success("查询成功",users);
}else{
return CommonResult.error("查询失败");
}
}
/*判断某个用户是否还存在*/
@RequestMapping(value = "/user/existKey")
private CommonResult existKey(String key) {
Boolean isExist = userService.existsWithPrimaryKey(key);
if(isExist!=null){
return CommonResult.success("查询成功",isExist);
}else{
return CommonResult.error("查询失败");
}
}
/*查询用户状态*/
@RequestMapping(value = "/user/userState")
private CommonResult userState(String accountNumber) {
Boolean state = userService.selectUserState(accountNumber);
if(state!=null){
return CommonResult.success("查询成功",state);
}else{
return CommonResult.error("查询失败");
}
}
/*查询用户记录的总条数*/
@RequestMapping(value = "/user/count")
}else{
return CommonResult.error("供货商查询失败");
}
}
/*查询全部供应商名称*/
@RequestMapping(value = "/supplier/findAllName")
private CommonResult findAllName() {
List<String> names = supplierService.selectAllName();
if(names!=null){
return CommonResult.success("供货商名称查询成功",names);
}else{
return CommonResult.error("供货商名称查询失败");
}
}
/*查询供应商是否存在*/
@RequestMapping(value = "/supplier/existSupplier")
private CommonResult existSupplier(Integer supplierId,String supplierName) {
Boolean isExist = supplierService.existsWithSupplierName(supplierId,supplierName);
if(isExist!=null){
return CommonResult.success("查询成功",isExist);
}else{
return CommonResult.error("查询失败");
}
}
/*添加供应商*/
@RequestMapping(value = "/supplier/addSupplier")
private CommonResult addSupplier(Supplier supplier) {
if(supplier!=null){
if(supplierService.insertData(supplier)){
return CommonResult.success("添加成功",supplier);
}else{
return CommonResult.error("添加失败");
}
}
return CommonResult.error("供应商数据不存在");
}
/*修改供应商*/
@RequestMapping(value = "/supplier/updateSupplier")
private CommonResult updateSupplier(Supplier supplier) {
if(supplier!=null){
if(supplierService.updateById(supplier)){
return CommonResult.success("更新成功",supplier);
}else{
return CommonResult.error("更新失败");
}
}
return CommonResult.error("供应商数据不存在");
return CommonResult.error("商品退款数据不存在");
}
/*拒绝买家退款申请*/
@RequestMapping(value = "/returnGoods/rejectRefund")
private CommonResult rejectRefund(Integer returnId,String operatorNumber,String operatorName) {
if(returnId!=null){
ReturnGoods returnGoods = returnGoodsService.selectById(returnId);
returnGoods.setReturnState("拒绝退款");
returnGoods.setDealTime(new Date());
returnGoods.setOperatorNumber(operatorNumber);
returnGoods.setOperatorName(operatorName);
String orderNo = returnGoods.getOrderNo();
Integer orderId = orderService.selectIdByKey(orderNo);
Order order = new Order();
order.setOrderId(orderId);
order.setOrderState("待发货");
if(orderService.updateById(order)){
if(returnGoodsService.updateById(returnGoods)){
return CommonResult.success("更新成功",returnGoods);
}else{
return CommonResult.error("更新失败");
}
}else {
return CommonResult.error("更新失败");
}
}
return CommonResult.error("商品退款数据不存在");
}
/*同意买家退货*/
@RequestMapping(value = "/returnGoods/dealWithReturn")
private CommonResult dealWithReturn(Integer returnId,String operatorNumber,String operatorName) {
if(returnId!=null){
ReturnGoods returnGoods = returnGoodsService.selectById(returnId);
returnGoods.setReturnState("允许退货");
returnGoods.setDealTime(new Date());
returnGoods.setOperatorNumber(operatorNumber);
returnGoods.setOperatorName(operatorName);
String orderNo = returnGoods.getOrderNo();
Integer orderId = orderService.selectIdByKey(orderNo);
Order order = new Order();
order.setOrderId(orderId);
order.setReturnState(true);
@RequestMapping(value = "/productReview/findById")
private CommonResult findById(Integer reviewId) {
ProductReview productReview = ProductReviewService.selectById(reviewId);
if(productReview!=null){
return CommonResult.success("商品评论查询成功",productReview);
}else{
return CommonResult.error("商品评论查询失败");
}
}
}
/**
* @email qiudb.top@aliyun.com
* @description 购物车业务类
*/
@RestController
@CrossOrigin
public class ShoppingCartController {
final ShoppingCartService shoppingCartService;
public ShoppingCartController(ShoppingCartService shoppingCartService){
this.shoppingCartService = shoppingCartService;
}
/*商品类别*/
@RequestMapping(value = "/shoppingCart/add")
private CommonResult addShoppingCart(ShoppingCart shoppingCart) {
if(shoppingCartService.insertData(shoppingCart)){
return CommonResult.success("购物车添加成功",shoppingCart);
}else{
return CommonResult.error("购物车添加失败");
}
}
@RequestMapping(value = "/shoppingCart/update")
private CommonResult updateShoppingCart(ShoppingCart shoppingCart) {
if(shoppingCartService.updateById(shoppingCart)){
return CommonResult.success("购物车修改成功",shoppingCart);
if(returnId!=null){
ReturnGoods returnGoods = new ReturnGoods();
returnGoods.setReturnId(returnId);
returnGoods.setReturnState("退货完成");
returnGoods.setDealTime(new Date());
if(returnGoodsService.updateById(returnGoods)){
return CommonResult.success("更新成功",returnGoods);
}else{
return CommonResult.error("更新失败");
}
}
return CommonResult.error("商品退货数据不完整");
}
@RequestMapping(value = "/returnGoods/deleteReturn")
private CommonResult deleteReturn(Integer returnId) {
if(returnId!=null){
if(returnGoodsService.deleteById(returnId)){
return CommonResult.success("删除成功",returnId);
}else{
return CommonResult.error("删除失败");
}
}
return CommonResult.error("商品退货数据不存在");
}
/*查询物流信息*/
@RequestMapping(value = "/logistics/findInfoById")
private CommonResult findInfoById(Integer logisticId) {
Logistics logistics = logisticsService.selectById(logisticId);
if(logistics!=null){
return CommonResult.success("物流信息查询成功",logistics);
}else{
return CommonResult.error("物流信息查询失败");
}
}
/*查询全部物流信息*/
@RequestMapping(value = "/logistics/findAllInfo")
private CommonResult findAllInfo() {
List<Logistics> logistics = logisticsService.selectAll();
if(logistics!=null){
return CommonResult.success("物流信息查询成功",logistics);
}else{
return CommonResult.error("物流信息查询失败");
}
}
@RequestMapping(value = "/logistics/addInfo")
private CommonResult addInfo(Logistics logistics) {
if(logistics!=null){
if(logisticsService.insertData(logistics)){
}else{
return CommonResult.error("删除失败");
}
}
return CommonResult.error("退货原因数据不存在");
}
/*查询商品退货信息*/
@RequestMapping(value = "/returnGoods/findReturnById")
private CommonResult findReturnById(Integer returnId) {
ReturnGoods returnGoods = returnGoodsService.selectById(returnId);
if(returnGoods!=null){
return CommonResult.success("退货商品查询成功",returnGoods);
}else{
return CommonResult.error("退货商品查询失败");
}
}
/*查询全部退货商品*/
@RequestMapping(value = "/returnGoods/findAllReturn")
private CommonResult findAllReturn() {
List<ReturnGoods> returnGoods = returnGoodsService.selectAll();
if(returnGoods!=null){
return CommonResult.success("退货商品查询成功",returnGoods);
}else{
return CommonResult.error("退货商品查询失败");
}
}
@RequestMapping(value = "/returnGoods/findCount")
private CommonResult findCount() {
Integer count = returnGoodsService.selectCount();
if(count!=null){
return CommonResult.success("退货订单数量查询成功",count);
}else{
return CommonResult.error("退货订单数量查询失败");
}
}
@RequestMapping(value = "/returnGoods/addReturn")
private CommonResult addReturn(ReturnGoods returnGoods) {
if(returnGoods!=null){
Integer orderId = orderService.selectIdByKey(returnGoods.getOrderNo());
System.out.println(returnGoods);
System.out.println(orderId);
Order order = new Order();
order.setOrderId(orderId);
order.setOrderState("待处理");
if (orderService.updateById(order)){
if(returnGoodsService.insertData(returnGoods)){
return CommonResult.success("添加成功",returnGoods);
}else{
Purchase purchase = new Purchase();
purchase.setPurchaseId(purchaseId);
purchase.setReceiptStatus(true);
purchase.setReceiptTime(new Date());
if(purchaseService.updateById(purchase)){
return CommonResult.success("收货成功",purchaseId);
}else{
return CommonResult.error("采购信息更新失败");
}
}else{
return CommonResult.error("商品库存更新失败");
}
}
}
/**
* @email qiudb.top@aliyun.com
* @description 用户相关业务
*/
@RestController
@CrossOrigin
public class UserController {
final RoleService roleService;
final UserService userService;
final UserRoleService userRoleService;
final VipService vipService;
public UserController(UserService userService, RoleService roleService,VipService vipService, UserRoleService userRoleService) {
this.userService = userService;
this.roleService = roleService;
this.userRoleService = userRoleService;
this.vipService = vipService;
}
private CommonResult findCount() {
Integer count = returnGoodsService.selectCount();
if(count!=null){
return CommonResult.success("退货订单数量查询成功",count);
}else{
return CommonResult.error("退货订单数量查询失败");
}
}
@RequestMapping(value = "/returnGoods/addReturn")
private CommonResult addReturn(ReturnGoods returnGoods) {
if(returnGoods!=null){
Integer orderId = orderService.selectIdByKey(returnGoods.getOrderNo());
System.out.println(returnGoods);
System.out.println(orderId);
Order order = new Order();
order.setOrderId(orderId);
order.setOrderState("待处理");
if (orderService.updateById(order)){
if(returnGoodsService.insertData(returnGoods)){
return CommonResult.success("添加成功",returnGoods);
}else{
return CommonResult.error("添加失败");
}
}else{
return CommonResult.error("添加失败");
}
}
return CommonResult.error("商品退货数据不存在");
}
@RequestMapping(value = "/returnGoods/updateReturn")
private CommonResult updateReturn(ReturnGoods returnGoods) {
if(returnGoods!=null){
returnGoods.setDealTime(new Date());
if(returnGoodsService.updateById(returnGoods)){
return CommonResult.success("更新成功",returnGoods);
}else{
return CommonResult.error("更新失败");
}
}
return CommonResult.error("商品退货数据不存在");
}
/**
* @email qiudb.top@aliyun.com
* @description 订单相关业务
*/
@RestController
@CrossOrigin
public class OrderController {
final OrderService orderService;
final ProductService productService;
final LogisticsService logisticsService;
final RedisTemplate<String,String> redisTemplate;
public OrderController(RedisTemplate<String,String> redisTemplate,OrderService orderService,LogisticsService logisticsService,ProductService productService) {
this.orderService = orderService;
this.productService = productService;
this.logisticsService = logisticsService;
this.redisTemplate = redisTemplate;
}
@RequestMapping(value = "/order/findById")
private CommonResult findOrderById(Integer orderId) {
Order order= orderService.selectById(orderId);
if(orderId!=null){
return CommonResult.success("订单信息查询成功",order);
}else{
return CommonResult.error("订单信息查询失败");
}
}
@RequestMapping(value = "/order/findOrderInfo")
private CommonResult findOrderInfo(String userAccount) {
List<Map<String, Object>> orderMap = orderService.selectAllOrder(userAccount);
return CommonResult.success("购物车删除成功","cartId: "+cartId);
}else{
return CommonResult.error("购物车删除失败");
}
}
@RequestMapping(value = "/shoppingCart/deleteByUser")
private CommonResult deleteByUser(String accountNumber) {
if(shoppingCartService.deleteByUser(accountNumber)){
return CommonResult.success("购物车删除成功","accountNumber: "+accountNumber);
}else{
return CommonResult.error("购物车删除失败");
}
}
@RequestMapping(value = "/shoppingCart/findAll")
private CommonResult findAllShoppingCart(String accountNumber) {
List<Map<String, Object>> shoppingInfo = shoppingCartService.selectAll(accountNumber);
if(shoppingInfo!=null){
return CommonResult.success("购物车查询成功",shoppingInfo);
}else{
return CommonResult.error("购物车查询失败");
}
}
@RequestMapping(value = "/shoppingCart/findById")
private CommonResult findById(Integer cartId) {
ShoppingCart shoppingCart = shoppingCartService.selectById(cartId);
if(shoppingCart!=null){
return CommonResult.success("购物车查询成功",shoppingCart);
}else{
return CommonResult.error("购物车查询失败");
}
}
}
/**
}
}
/**
* @email qiudb.top@aliyun.com
* @description 用户授权等相关业务
*/
@RestController
@CrossOrigin
public class RoleController {
final RoleService roleService;
public RoleController(RoleService roleService) {
this.roleService = roleService;
}
/*根据id查询用户*/
@RequestMapping(value = "/role/findById")
private CommonResult findById(Integer roleId) {
Role role = roleService.selectById(roleId);
if(role!=null){
return CommonResult.success("查询成功",role);
}else{
return CommonResult.error("查询失败");
}
}
/*根据角色名称查询角色*/
@RequestMapping(value = "/role/findByKey")
private CommonResult findByKey(String roleName) {
Role role = roleService.selectByKey(roleName);
if(role!=null){
return CommonResult.success("查询成功",role);
if(vipService.deleteById(vipId)){
return CommonResult.success("删除成功",vipId);
}else{
return CommonResult.error("删除失败");
}
}
}
@CrossOrigin
@RequestMapping("/alipay")
@Slf4j
@Controller
public class AlipayController {
private final AlipayService alipayService;
private final OrderService orderService;
private final RedisTemplate<String,String> redisTemplate;
private final String hostAddress;
public AlipayController(AlipayService alipayService,OrderService orderService,RedisTemplate<String,String> redisTemplate) {
this.alipayService = alipayService;
this.orderService = orderService;
this.redisTemplate = redisTemplate;
this.hostAddress= PropertiesUtil.getServerHost() +":"+PropertiesUtil.getPort();
}
@RequestMapping("/")
private String index(){
return "index.html";
}
/*
https://qiustudy.utools.club/alipay/create?orderNo=10060&orderName=花卷商城-华为手机支付订单&payPrice=4000
*/
@ResponseBody
@PostMapping(value = "/create", produces = "text/html;charset=utf-8")
public void create(@RequestParam("orderNo") String orderNo,
@RequestParam("orderName") String orderName,
@RequestParam("payPrice") String payPrice
Map<String, Object> info = new HashMap<>();
String authorization = (String) subject.getSession().getId();
User user;
if (username.contains("@")) {
//包含@符号,代表用户通过邮箱帐号登录
user = userService.selectByKey(username);
} else {
//不包含@符号,代表用户通过手机号登录
user = userService.selectByPhone(username);
}
info.put("user", user); //存放用户信息
//更新最后登录时间
user.setLoginTime(new Date());
userService.updateById(user);
//存放sessionId, 即 token
info.put("sessionId", authorization);
List<Role> roles = roleService.selectAll();
List<String> rs = new ArrayList<>(); // rs 存放的是role的名称
List<String> rsInfo = new ArrayList<>(); //rsInfo 存放role的描述
for (Role role : roles) {
rs.add(role.getRoleName());
rsInfo.add(role.getRoleName());
}
boolean[] booleans = subject.hasRoles(rs);
for (int i = booleans.length - 1; i >= 0; i--) {
if (!booleans[i]) {
rs.remove(i);
rsInfo.remove(i);
}
}
info.put("role", rs);
info.put("roleInfo", rsInfo);
return CommonResult.success("登录成功", info);
}catch (LockedAccountException e){
return CommonResult.error("您的帐号存在异常行为,已被封停(请联系工作人员)");
} catch (IncorrectCredentialsException e) {
return CommonResult.error("密码错误,请重新输入");
} catch (AuthenticationException e) {
return CommonResult.error("该用户不存在");
}
}
/**
* 退出登录操作
* @param key 用户登录的帐号
* @param session 前端存储的session(token)
*/
@RequestMapping(value = "/logout")
private CommonResult logout(String key,String session) {