Browse Source

文件上传(多个/单个)

master
zy_Java 4 years ago
parent
commit
7aa4b67211
  1. 15
      src/main/java/com/ccsens/defaultwbs/api/FileController.java
  2. 2
      src/main/java/com/ccsens/defaultwbs/service/FileService.java
  3. 4
      src/main/resources/application.yml

15
src/main/java/com/ccsens/defaultwbs/api/FileController.java

@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
/**
@ -28,15 +29,21 @@ public class FileController {
@Resource
private IFileService fileService;
@MustLogin
@MustLogingit
@ApiOperation(value = "上传文件",notes = "文件大小不能超过20M")
@ApiImplicitParams({
})
@RequestMapping(value = "upload", method = RequestMethod.POST,produces = {"application/json;charset=UTF-8"})
public JsonResponse<List<FileVo.FileInfo>> uploadFile(QueryDto<List<MultipartFile>> params) throws Exception {
public JsonResponse<List<FileVo.FileInfo>> uploadFile(QueryDto<MultipartFile> params) throws Exception {
log.info("上传文件:{}",params);
// MultipartFile f = params.getParam();
List<FileVo.FileInfo> fileInfoList = fileService.uploadFile(params.getParam(),params.getUserId());
List<MultipartFile> fileList;
try {
fileList = (List<MultipartFile>) params.getParam();
}catch (Exception e){
fileList = new ArrayList<>();
fileList.add(params.getParam());
}
List<FileVo.FileInfo> fileInfoList = fileService.uploadFile(fileList,params.getUserId());
return JsonResponse.newInstance().ok(fileInfoList);
}

2
src/main/java/com/ccsens/defaultwbs/service/FileService.java

@ -40,7 +40,7 @@ public class FileService implements IFileService {
@Override
public List<FileVo.FileInfo> uploadFile(List<MultipartFile> fileList, Long userId) throws Exception {
if(CollectionUtil.isNotEmpty(fileList)){
if(CollectionUtil.isEmpty(fileList)){
throw new BaseException(DefaultCodeError.NOT_FILE);
}
List<FileVo.FileInfo> fileInfoList = new ArrayList<>();

4
src/main/resources/application.yml

@ -1,4 +1,4 @@
spring:
profiles:
active: test
include: common, util-test
active: dev
include: common, util-dev

Loading…
Cancel
Save