gpt4 book ai didi

java - 以 thymeleaf 形式传播对象

转载 作者:行者123 更新时间:2023-12-02 03:26:46 24 4
gpt4 key购买 nike

我有一个包含两个表单的页面,并且想在提交第二个表单时添加第一个表单中的对象。基本上它看起来像这样:第一种形式:

<form action="#" method="POST" enctype="multipart/form-data" th:action="@{/foo}" th:object="${prop1}" id="form1">
<input type="file" name="file" class="form-control"/>
<input type="text" th:value="${prop1.taskSheetName}" name="taskSheetName"/>
<input type="number" th:value="${prop1.descriptionColumnPosition}" name="descriptionColumnPosition"/>
</form>

第二种形式:

<form th:if="${resourceId}" action="#" method=" th:object="${prop2}" id="prop2" th:action="@{/foo/{id}(id=${resourceId})}">
<input type="url" th:value="${prop2.url}" name="url"/>
<input type="text" th:value="${prop2.username}" name="username"/>
<input type="password" th:value="${prop2.password}" name="password"/>
</form>

和 Controller 方法:

@RequestMapping(value = "/foo", method = POST)
public String uploadFile(@RequestParam("file") MultipartFile file, final ExcelProperties properties, final Model model) {
//some logic here
}

@RequestMapping(value = "/process/{id}", method = POST)
public String processResource(@PathVariable("id") String id, final Prop2 prop2, final Prop1 prop1, final Model model) {
}

我需要将值从第一个表单值传递到具有第二个表单值的第二个方法,但它传递空表单对象。我尝试添加

<div th:with="p1=${prop1}">

因为我知道这些数据存在于页面中,但没有帮助。
如果这可能的话,或者我应该放弃并用 JavaScript 编写自定义提交处理程序?

最佳答案

根据MDN ,不可能将 1 个输入附加到 2 个表单中,

您需要使用 JavaScript 进行一些工作。

关于java - 以 thymeleaf 形式传播对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38744110/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com