电商项目(八)--添加商品之处理图片上传

本文详细介绍了在电商项目中处理商品图片上传的过程,包括在backend_item服务的controller、service、serviceImpl层面的实现,以及配置文件的修改,同时添加了FTPUtil工具类和common-net依赖来支持文件传输。
摘要由CSDN通过智能技术生成

1. 在backend_item服务中处理图片上传

1.1 controller
package com.bjsxt.backenditem.controller;

import com.bjsxt.backenditem.service.FileUploadService;
import com.bjsxt.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;

/**
 * 图片上传
 */
@RestController
@RequestMapping("/file")
public class FileUploadController {
   
    @Autowired
    private FileUploadService fileUploadService;
    /**
     * 图片上传
     */
    @RequestMapping("/upload")
    public Result fileUpload(MultipartFile file){
   
        try{
   
            Result result = fileUploadService.fileUpload(file);
            return result;

        }catch (Exception e){
   
            e.printStackTrace();
        }
        return Result.build(500,"error");

    }

}

1.2 service
package com.bjsxt.backenditem.service;

import com.bjsxt.utils.Result;
import org.springframework.web.multipart.MultipartFile;

public interface FileUploadService {
   
    Result fileUpload(MultipartFile file);

}

1.3 serviceImpl
package com.bjsxt.backenditem.service.impl;

import com.bjsxt.backenditem.service.FileUploadService;

import com.bjsxt.utils.FtpUtil;
import com.bjsxt.utils.IDUtils;
import com.bjsxt.utils.Result;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

@Service
public class Fil
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值