java - 如何在 Thymeleaf 中提交二维数组?
问题描述
我正在尝试提交包含两个维度数组的表单。你能检查我的代码并告诉我它有什么问题吗?
形式:
public class SimpleForm {
private String[][] twoDimentionArray;
public String[][] getTwoDimentionArray() {
return twoDimentionArray;
}
public void setTwoDimentionArray(String[][] twoDimentionArray) {
this.twoDimentionArray = twoDimentionArray;
}
}
百里香叶:
<form action="#" th:action="@{/save-form} th:object="${form}" method="post">
<input type="text" th:field="*{twoDimentionArray[0][0]}"/>
<input type="submit" value="Submit" />
</form>
出现以下错误:
java.lang.IllegalArgumentException: array element type mismatch
at java.lang.reflect.Array.set(Native Method) ~[na:1.8.0_171]
at org.springframework.beans.AbstractNestablePropertyAccessor.processKeyedProperty(AbstractNestablePropertyAccessor.java:311) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:275) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:266) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:97) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.validation.DataBinder.applyPropertyValues(DataBinder.java:839) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.validation.DataBinder.doBind(DataBinder.java:735) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.web.bind.WebDataBinder.doBind(WebDataBinder.java:197) ~[spring-web-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.web.bind.ServletRequestDataBinder.bind(ServletRequestDataBinder.java:107) ~[spring-web-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletModelAttributeMethodProcessor.bindRequestParameters(ServletModelAttributeMethodProcessor.java:157) ~[spring-webmvc-5.0.4.RELEASE.jar:5.0.4.RELEASE]
解决方案
你传递你的数组错误。尝试这个
<form action="#" th:action="@{/save-form}" th:object="${form}" method="post">
<div th:each="1d, i: *{twoDimentionArray}">
<div th:each="test, j: *{1d}">
<input type="text" th:field="*{userAddresses[__${i.index}__][__${j.index}__]}" />
</div>
</div>
<input type="submit" value="Submit" />
</form>
推荐阅读
- pagespeed - 在哪里放置GoogleSite
- javascript - D3 版本 5 自定义 x 轴值
- tensorflow - Tensorflow 对象检测 API 评估 mAP 随机变为 0
- python - 矢量化 scipy norm.pdf
- django - Django:从请求中删除cookie
- verilog - 我需要生成如图所示的波形。在verilog代码中
- ios - 如何使用 MTLRenderPassDescriptor 加载现有纹理
- django - 我可以为 django-allauth 使用“帐户”以外的 URL 吗?我的 django 项目中已经有一个名为“accounts”的应用程序?
- python - mysql连接器按列名而不是索引调用
- jsoup - jsoup select中组合器的评估顺序