【发布时间】:2017-08-23 16:06:26
【问题描述】:
在我的网页中,我想显示一个包含所有性质的列表,并且我希望将选定的性质设置在一个列表中。
我的问题是该列表在我显示的列表中正确设置,但未在所选元素列表中设置:自然。确实,不是我本性的属性字符串“nom”,而是存储它的引用:fr.cnamts.navigo.domain.Nature@19c4a02 by instance
这里是复选框显示:
我想要什么:当我通过实例检查 2 拳头复选框时,我希望在我的控制器中拥有 List<Nature> natures 值
natures.get(0).nom = "bcmc_envtraco_out"
natures.get(0).routage = INSTANCE
natures.get(1).nom = "bcmc_medtab_out"
natures.get(1).routage = INSTANCE
当它之前工作时,复选框是list<String>,我认为出现问题是因为我使用list<Nature>做错了。
这是我的相关网页代码:
<form action="#" th:action="@{/bus/topologie}"
th:object="${topologie}" method="post" class="form-horizontal">
<div class="col-sm-10" th:if="!${#lists.isEmpty(allNature)}">
<div th:each="nature : ${allNature}" class="checkbox">
<label th:for="${#ids.next('nature')}">
<input type="checkbox" th:field="*{natures}" th:value="${nature}" class="checkboxNature" />
<span th:text="${nature.nom}" class="col-sm-5">...</span>
<span th:text="${nature.routage.nom}" class="col-sm-5">...</span>
</label>
</div>
这段代码是这样解释的(复制自 chrome 中的 html 代码):
<div class="checkbox">
<label for="nature1">
<input type="checkbox" class="checkboxNature" value="fr.cnamts.navigo.domain.Nature@19c4a02" id="natures3" name="natures"><input type="hidden" name="_natures" value="on">
<span class="col-sm-5">bcmc_trabcmreca_out</span>
<span class="col-sm-7">Routage sur instance</span>
</label>
</div>
我的控制器中的相关代码:
@ModelAttribute("allNature")
public List<Nature> getAllNatures(Topologie topologie) throws Exception
{
return natureService.getNaturesByVersionCadre(topologie.getCadre(), topologie.getVersionCadre());
}
以及我的对象“拓扑”中的相关代码:
public class Topologie {
private List<Nature> natures = new ArrayList<Nature>();
最后是自然类:
public class Nature {
@NotBlank
private String nom;
@NotNull
private Routage routage;
// @NotNull
// private String typeCl;
public enum Routage {
INSTANCE("Routage sur instance", "^[A-Za-z0-9]{2}$ (instance)"), UCANSS(
"Routage sur code UCANSS", "^[A-Za-z0-9]{2}$ (Code UCANSS)"), ACOSS(
"Routage sur code ACOSS", "^[A-Za-z0-9]{2}$ (Code ACOSS)"), INSTANCE_MIAM(
"Routage sur code instance MIAM", "^[A-Za-z0-9]{2}$ (instance)"), CODEREGIME_CODECAISSE(
"Routage sur coderégime+code caisse",
"^[0-9]{2}[0-9]{3}$ (Code régime code caisse)");
private final String nomRoutage;
// private final String codecle;
private final String regExp;
Routage(String nom, String regexp) {
this.nomRoutage = nom;
this.regExp = regexp;
}
public String getNom() {
return nomRoutage;
}
public String getRegExp() {
return regExp;
}
}
public Nature(String nomNature) {
nom = nomNature;
// TODO à modifier une fois récup faite dans fichier zk
routage = Routage.INSTANCE;
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
public Routage getRoutage() {
// TODO à modifier une fois récup faite dans fichier zk
if (routage == null) {
routage = Routage.INSTANCE;
}
return routage;
}
public void setRoutage(Routage routage) {
// TODO à modifier une fois récup faite dans fichier zk
if (routage == null) {
routage = Routage.INSTANCE;
}
this.routage = routage;
}
}
【问题讨论】:
标签: spring-boot thymeleaf