提交 b5fee5bf authored 作者: mry's avatar mry

添加了文件上传功能暂未实现

上级 35699565
package com.jenkins.controller;
import com.jenkins.service.FileService;
import com.jenkins.vo.FileVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.nio.channels.MulticastChannel;
@CrossOrigin
@RestController
@RequestMapping("/files")
@Api(tags = "添加文件",description = "上床文件到本地")
public class FileController {
private final FileService fileService;
public FileController(FileService fileService) {
this.fileService = fileService;
}
@PostMapping
public ResponseEntity<FileVo> upload(MultipartFile file){
FileVo fileVo = fileService.upload(file);
if (fileVo == null){
return ResponseEntity.status(404).body(fileVo);
}else {
return ResponseEntity.ok(fileVo);
}
}
}
package com.jenkins.service;
import com.jenkins.vo.FileVo;
import org.springframework.web.multipart.MultipartFile;
public interface FileService {
FileVo upload(MultipartFile file);
}
package com.jenkins.service.Impl;
import com.jenkins.service.FileService;
import com.jenkins.vo.FileVo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
@Service
public class FileServiceImpl implements FileService {
@Value("${file.localDirPath}")
private String localDirPath; //本地磁盘地址
@Override
public FileVo upload(MultipartFile file) {
String fileName = file.getOriginalFilename();
return null;
}
}
package com.jenkins.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.Accessors;
@Setter
@Getter
@ToString
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
@ApiModel(value = "文件回显信息")
public class FileVo {
@ApiModelProperty(value = "文件上传后的名字")
private String fileName;
@ApiModelProperty(value = "文件全路径,不包含本地磁盘")
private String filePath;//文件路径
}
file.localDirPath=D:/file
\ No newline at end of file
server:
port: 8888
spring:
datasource:
url: jdbc:mysql://localhost:3306/jpa?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: root
jpa:
hibernate:
ddl-auto: update
show-sql: true
database: mysql
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论