咖啡商城|基于Springboot+Vue前后端分离咖啡商城系统(二)

简介: 咖啡商城|基于Springboot+Vue前后端分离咖啡商城系统

咖啡商城|基于Springboot+Vue前后端分离咖啡商城系统(一)https://developer.aliyun.com/article/1423367


三,系统展示

系统首页


分类展示

商品详情


前端用户注册登陆

购物车

下单支付:点支付从充值卡里扣除,如不够则进入支付宝沙箱支付平台

商品资讯

个人中心:可以实现在线充值

我的订单

用户管理

商品分类管理

商品管理

评价管理

轮播图管理

商品资讯

四,核心代码展示

package com.controller;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.annotation.IgnoreAuth;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.entity.ConfigEntity;
import com.entity.EIException;
import com.service.ConfigService;
import com.utils.R;
/**
 * 上传文件映射表
 */
@RestController
@RequestMapping("file")
@SuppressWarnings({"unchecked","rawtypes"})
public class FileController{
  @Autowired
    private ConfigService configService;
  /**
   * 上传文件
   */
  @RequestMapping("/upload")
  public R upload(@RequestParam("file") MultipartFile file,String type) throws Exception {
    if (file.isEmpty()) {
      throw new EIException("上传文件不能为空");
    }
    String fileExt = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")+1);
    //File path = new File(ResourceUtils.getURL("classpath:static").getPath());
    String path2 = ResourceUtils.getFile("classpath:static").getAbsolutePath();
    /*if(!path.exists()) {
        path = new File("");
    }*/
    File upload = new File(path2,"/upload/");
    if(!upload.exists()) {
        upload.mkdirs();
    }
    String fileName = new Date().getTime()+"."+fileExt;
    File dest = new File(upload.getAbsolutePath()+"/"+fileName);
    file.transferTo(dest);
    if(StringUtils.isNotBlank(type) && type.equals("1")) {
      ConfigEntity configEntity = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "faceFile"));
      if(configEntity==null) {
        configEntity = new ConfigEntity();
        configEntity.setName("faceFile");
        configEntity.setValue(fileName);
      } else {
        configEntity.setValue(fileName);
      }
      configService.insertOrUpdate(configEntity);
    }
    return R.ok().put("file", fileName);
  }
  /**
   * 下载文件
   */
  @IgnoreAuth
  @RequestMapping("/download")
  public ResponseEntity<byte[]> download(@RequestParam String fileName) {
    try {
      File path = new File(ResourceUtils.getURL("classpath:static").getPath());
      if(!path.exists()) {
          path = new File("");
      }
      File upload = new File(path.getAbsolutePath(),"/upload/");
      if(!upload.exists()) {
          upload.mkdirs();
      }
      File file = new File(upload.getAbsolutePath()+"/"+fileName);
      if(file.exists()){
        /*if(!fileService.canRead(file, SessionManager.getSessionUser())){
          getResponse().sendError(403);
        }*/
        HttpHeaders headers = new HttpHeaders();
          headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
          headers.setContentDispositionFormData("attachment", fileName);
          return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),headers, HttpStatus.CREATED);
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
    return new ResponseEntity<byte[]>(HttpStatus.INTERNAL_SERVER_ERROR);
  }
}


咖啡商城|基于Springboot+Vue前后端分离咖啡商城系统(三)https://developer.aliyun.com/article/1423369

相关文章
|
1天前
|
JSON JavaScript Java
从前端Vue到后端Spring Boot:接收JSON数据的正确姿势
从前端Vue到后端Spring Boot:接收JSON数据的正确姿势
25 0
|
1天前
|
JavaScript 前端开发 BI
采用前后端分离Vue,Ant-Design技术开发的(手麻系统成品源码)适用于三甲医院
开发环境 技术架构:前后端分离 开发语言:C#.net6.0 开发工具:vs2022,vscode 前端框架:Vue,Ant-Design 后端框架:百小僧开源框架 数 据 库:sqlserver2019
28 4
采用前后端分离Vue,Ant-Design技术开发的(手麻系统成品源码)适用于三甲医院
|
1天前
|
JavaScript 测试技术 开发者
Vue 3 Vuex:构建更强大的状态管理系统
Vue 3 Vuex:构建更强大的状态管理系统
23 1
|
1天前
|
JavaScript 前端开发 开发者
Vue的响应式原理:深入探索Vue的响应式系统与依赖追踪
【4月更文挑战第24天】Vue的响应式原理通过JavaScript getter/setter实现,当数据变化时自动更新视图。它创建Watcher对象收集依赖,并通过依赖追踪机制精确通知更新。当属性改变,setter触发更新相关Watcher,重新执行操作以反映数据最新状态。Vue的响应式系统结合依赖追踪,有效提高性能,简化复杂应用的开发,但对某些复杂数据结构需额外处理。
|
1天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的4S店客户管理系统的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的4S店客户管理系统的详细设计和实现
47 4
|
1天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的在线课堂微信小程序的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的在线课堂微信小程序的详细设计和实现
35 3
|
1天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的微信课堂助手小程序的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的微信课堂助手小程序的详细设计和实现
58 3
|
1天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的商品展示的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的商品展示的详细设计和实现
33 3
|
1天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的电子商城购物平台的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的电子商城购物平台的详细设计和实现
53 3
|
1天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的英语学习交流平台的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的英语学习交流平台的详细设计和实现
32 2