我是开发和Spring Boot的新手.. 我想创建一个上传文件的应用程序并显示它的哈希值 我设法创建一个基本的应用程序,但当我尝试做一个表单和“POST” 我在STS控制台上收到以下错误的文件: 请求方法“POST”不受支持 能否请你帮忙? 这是我的控制器代码:
package controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/")
public class FileUploadController {
@RequestMapping(value = "/", method = RequestMethod.POST)
public void downloadFile(@RequestParam(value="file") String file){
}
}
答案 0 :(得分:0)
@PostMapping("/")
public String handleFileUpload(@RequestParam("file") MultipartFile file,
RedirectAttributes redirectAttributes) {
storageService.store(file);
redirectAttributes.addFlashAttribute("message",
"You successfully uploaded " + file.getOriginalFilename() + "!");
return "redirect:/";
}
<form method="POST" enctype="multipart/form-data" action="/">
<table>
<tr><td>File to upload:</td><td><input type="file" name="file" /></td></tr>
<tr><td></td><td><input type="submit" value="Upload" /></td></tr>
</table>
</form>
答案 1 :(得分:0)
我想我明白了。 我已经删除了存储服务,只是将重定向发布到test.html 它工作正常 我只需要知道如何操作这个文件并将其哈希值返回给web应用程序
update [Table] set [Count]= isnull((select top 1 [Previous].[Count]
from [Table] as [Previous]
where [Previous].[Count] <> 0 and
[Previous].[Date] <= [Table].[Date] and
[Previous].[Id] = [Table].[Id]
order by [Previous].[Date] desc),
0) as [Count]
谢谢你们!