我试图使用spring bootstrap创建一个更新方法,但它在get中给了我错误。
@RequestMapping(value = "/file", method = GET)
字符串
我正在获取文件路径未找到/file/upload/
@RestController
@RequestMapping(value = "/file", method = GET)
public class FileResource {
// define a location
public static final String DIRECTORY = System.getProperty("user.home") + "/Downloads/";
// method for upload
@PostMapping("/upload")
public ResponseEntity<List<String>> uploadFiles(@org.jetbrains.annotations.NotNull @RequestParam("files")List<MultipartFile> MultipartFile) throws IOException {
List<String> filenames = new ArrayList<>();
for (MultipartFile file : MultipartFile) {
String filename = StringUtils.cleanPath(Objects.requireNonNull(file.getOriginalFilename()));
Path fileStorage = get(DIRECTORY, filename).toAbsolutePath().normalize();
copy(file.getInputStream(), fileStorage, REPLACE_EXISTING);
filenames.add(filename);
}
return ResponseEntity.ok().body(filenames);
}
}
型
1条答案
按热度按时间lnlaulya1#
由于
FileResource
是您的控制器,因此您不应该将method = GET
放在@RequestMapping
上。请将其删除并尝试再次发送POST希望它能帮助