附件上传

引入依赖

<dependency>
  <groupId>com.wueasy</groupId>
  <artifactId>wueasy-cloud-web-file</artifactId>
  <version>最新版本</version>
</dependency>

工具类

工具类文件路径com.wueasy.cloud.web.file.util.FileUitl

public class FileUitl {

    /**
     * 上传文件
     * @author: fallsea
     * @param file
     * @return
     * @throws InvokeException
     */
    public static FileEntity upload(MultipartFile file);

    /**
     * 上传文件
     * @author: fallsea
     * @param file
     * @param businessType 业务类型
     * @return
     * @throws InvokeException
     */
    public static FileEntity upload(MultipartFile file,String businessType);
}

配置servlet接收文件大小

如果未配置,提交大一点的文件,将会出现错误。

spring:
  servlet:
    multipart:
      max-file-size: 100MB
      max-request-size: 100MB

示例

/**
 * 附件上传
 * @author: fallsea
 * @version 1.0
 */
@RestController
@RequestMapping("/file")
public class FileController {

    /**
     * 上传单个文件
     * @author: fallsea
     * @param file
     * @param businessType
     * @param response
     * @return
     */
    @RequestMapping(value = "/upload", method = { RequestMethod.POST }, produces = MediaType.APPLICATION_JSON_VALUE)
    public Result<FileEntity> upload(@RequestParam("file") MultipartFile file,@RequestParam(value ="businessType",required = false)String businessType, HttpServletResponse response) {
        FileEntity fileEntity = FileUitl.upload(file,businessType);
        return new Result<FileEntity>().setData(fileEntity);
    }

}

配置说明

参考配置说明

Copyright © wueasy.com 2017-2022 all right reserved,powered by Gitbook未经允许,禁止以任何形式传播 修订时间: 2022-09-10

results matching ""

    No results matching ""