为什么我得到错误在我得到调用使用spring bootstrao

lymnna71  于 7个月前  发布在  Spring
关注(0)|答案(1)|浏览(70)

我试图使用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);
    }
}

lnlaulya

lnlaulya1#

由于FileResource是您的控制器,因此您不应该将method = GET放在@RequestMapping上。请将其删除并尝试再次发送POST
希望它能帮助

相关问题