spring-boot - 无法从模板中保存带有其他文本详细信息的文件,这会导致“所需的请求部分‘文件’不存在”这个错误
问题描述
我的控制器
@PostMapping
public String registerUserAccount(@ModelAttribute("user") @Valid User user,
BindingResult result, @RequestParam("file") MultipartFile file) throws IOException{
byte[] pic = file.getBytes();
User imageUser = new User(pic);
userService.save(user);
userService.save(imageUser);
return "redirect:/registration?success";
}
我正在通过服务保存来自控制器的图像和其他文本细节
我的模板
<form class="login100-form validate-form" th:action="@{/registration}" th:object="${user}" method="post" enctype="multipart/form-data">
//other textual inputs like name address and number
<label for="Profile Picture">Profile Picture</label>
<input type="file" name="file" placeholder="Pofile Picture" th:field="*{pic}">
</div>
解决方案
推荐阅读
- python - 如何将 csv 文件转换为具有 unicode utf-8 编码的文件并保持法语口音?
- r - 根据重复的 ID 变量删除 NA
- javascript - 将innerHTML保存到文本文件时换行符我在保存的文本文件中或重新加载页面时自动获得换行符
- javascript - 测试 Angular 的 index.html 页面是否可行?
- c# - 映射 IEnumerable 时如何映射自定义属性
- c++ - 错误 C2440:“正在初始化”:无法从“const char *”转换为“TCHAR *”
- jenkins - 如何逃脱 - (连字符)使用 groovy 语言
- r - 使用建议的起始值从长转换为宽的问题
- hashicorp-vault - Hashicorp Vault 快照解密
- angular-material - 如何向有角度的材质滑块(垫滑块)添加额外的静态拇指标签?