Forráskód Böngészése

后台图片上传

limingming 1 éve
szülő
commit
498a3fbca6

+ 0 - 2
ruoyi-admin/src/main/java/com/ruoyi/web/controller/platform/QrLibraryController.java

@@ -62,9 +62,7 @@ public class QrLibraryController extends BaseController {
     /**
      * 新增修改二维码
      */
-
 //    @PreAuthorize("@ss.hasPermi('platform:or:add')")
-
     @Log(title = "红外遥控二维码", businessType = BusinessType.INSERT)
     @PostMapping("/addOrUpdate")
     public R<Boolean> add(@RequestBody QrLibrary param) {

+ 38 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/platform/UploadController.java

@@ -0,0 +1,38 @@
+package com.ruoyi.web.controller.platform;
+
+import com.ruoyi.common.config.RuoYiConfig;
+import com.ruoyi.common.core.domain.R;
+import com.ruoyi.common.utils.file.FileUploadUtils;
+import com.ruoyi.system.domain.UploadInfo;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.IOException;
+
+/**
+ * @Author: LiMingMing
+ * @Date: 2023/7/20 16:24
+ * @Description: 上传文件图片
+ **/
+@RestController
+@RequestMapping("/platform/v1/upload")
+public class UploadController {
+
+    @ResponseBody
+    @PostMapping("/uploadImage")
+    public R<UploadInfo> addSave(@RequestParam("file") MultipartFile file, @RequestParam("fileName") String fileName) throws IOException {
+        // 上传文件路径
+        String filePath = RuoYiConfig.getUploadPath();
+        // 上传并返回新文件名称
+        String fileNewName = FileUploadUtils.upload(filePath, file);
+        UploadInfo uploadInfo = new UploadInfo();
+
+        uploadInfo.setFileName(fileName);
+        uploadInfo.setUrl(filePath+fileNewName);
+
+        //返回文件名 和存放路径
+        return R.ok(uploadInfo);
+    }
+
+
+}

+ 4 - 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/QrLibrary.java

@@ -28,6 +28,10 @@ public class QrLibrary  implements Serializable {
     @Excel(name = "二维码名称")
     private String name;
 
+    /** 二维码名称 */
+    @Excel(name = "上传图片名称")
+    private String imageName;
+
     /** 二维码连接 */
     @Excel(name = "二维码连接")
     private String url;

+ 24 - 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/UploadInfo.java

@@ -0,0 +1,24 @@
+package com.ruoyi.system.domain;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @Author: LiMingMing
+ * @Date: 2023/7/20 16:34
+ * @Description: TODO
+ **/
+@Data
+public class UploadInfo implements Serializable {
+
+    /**
+     * 文件名
+     */
+    private String fileName;
+
+    /**
+     * 文件地址
+     */
+    private String url;
+}

+ 2 - 1
ruoyi-system/src/main/resources/mapper/system/platform/QrLibraryMapper.xml

@@ -7,6 +7,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <resultMap type="QrLibrary" id="QrLibraryResult">
         <result property="id"    column="id"    />
         <result property="name"    column="name"    />
+        <result property="imageName"    column="image_name"    />
         <result property="url"    column="url"    />
         <result property="status"    column="status"    />
         <result property="delFlag"    column="del_flag"    />
@@ -17,7 +18,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </resultMap>
 
     <sql id="selectQrLibraryVo">
-        select id, name, url, status, del_flag, create_by, create_time, update_by, update_time from t_qr_library
+        select id, image_name, name, url, status, del_flag, create_by, create_time, update_by, update_time from t_qr_library
     </sql>