【发布时间】:2017-08-24 18:49:11
【问题描述】:
我想在一个隐藏字段绑定一个枚举,以便在提交表单时保留信息。不知何故,枚举的字段为空。
我的对象看起来像:
public class Check {
@NotNull private String name;
@NotNull private CheckType type; // ENUM with GETTER & SETTER
// BESIDE NORMAL GETTER & SETTER ANOTHER TRY ...
public String getTypeName() {
return type == null ? null : type.name();
}
public void setTypeName(String name) {
type = CheckType.valueOf(name);
}
...
}
在我的 Thymeleaf-Template 中,我正在遍历对象并希望保留枚举:
<input type="hidden" th:field="*{checks[__${checkStat.index}__].type}" />
<!-- ALSO TRIED ... -->
<input type="hidden" th:field="*{checks[__${checkStat.index}__].typeName}" />
发送Form后,type为null。我错过了什么?
【问题讨论】:
标签: forms spring-mvc spring-boot enums thymeleaf