Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
293 views
in Technique[技术] by (71.8m points)

java - 百里香叶绑定文件到对象(thymeleaf bind file to object)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...