i am trying to bind multiple files to an object as a byte array, but thymeleaf instead it bind only file names as a byte array.
(我试图将多个文件作为字节数组绑定到一个对象,但是百里香相反,它仅将文件名作为字节数组绑定。)
How can i catch file in controller? (如何在控制器中捕获文件?)
or bind file bytes? (或绑定文件字节?)
Html:
(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 like:
(testObject像:)
public class TestObject {
...
@Column(name = "privatekey")
private byte[] privatekey;
@Column(name = "publickey")
private byte[] publickey;
}
Controller:
(控制器:)
@PostMapping("/add")
public String singleFileUpload(@ModelAttribute("testObject") TestObject testObject,
RedirectAttributes redirectAttributes,
Principal principal) {
testObjectService.save(testObject);
return "redirect:test/page";
}
ask by Пётр П translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…