여러 파일을 바이트 배열로 객체에 바인딩하려고하지만 thymeleaf는 파일 이름 만 바이트 배열로 바인딩합니다. 컨트롤러에서 파일을 어떻게 잡을 수 있습니까? 또는 바인딩 파일 바이트?
HTML :
<form th:action="@{/add}" th:object="${testObject}" method="post">
<span>add key</span>
<input class="btn btn-primary btn-sm" th:field="*{privatekey}" type="file" name="file">
<span>add key</span>
<input class="btn btn-primary btn-sm" th:field="*{publickey}" type="file" name="file">
<button type="submit">Seve</button>
testObject는 다음과 같습니다.
public class TestObject {
...
@Column(name = "privatekey")
private byte[] privatekey;
@Column(name = "publickey")
private byte[] publickey;
}
제어 장치:
@PostMapping("/add")
public String singleFileUpload(@ModelAttribute("testObject") TestObject testObject,
RedirectAttributes redirectAttributes,
Principal principal) {
testObjectService.save(testObject);
return "redirect:test/page";
}