Невозможно сохранить файл с другими текстовыми данными из шаблона, что приводит к этой ошибке «Обязательная часть запроса:« файл »отсутствует» - PullRequest
0 голосов
/ 26 марта 2020

Мой контроллер

@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>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...