Spring 是否不可能在一个控制器中使用两个@ModelAttribute?
我有一个页面jsp,其中我将使用来自不同类的许多属性,因此我需要在控制器中使用两个@modeldattribute。另外,如果我在一个控制器中使用两个@modeldattribute,我必须在表单中放入两个commandName。可能吗 这是我的表单:(Fonction是Activite类中的一个属性,而etablisement的名称是etablisement类中的一个属性:Spring 是否不可能在一个控制器中使用两个@ModelAttribute?,spring,model-view-controller,Spring,Model View Controller,我有一个页面jsp,其中我将使用来自不同类的许多属性,因此我需要在控制器中使用两个@modeldattribute。另外,如果我在一个控制器中使用两个@modeldattribute,我必须在表单中放入两个commandName。可能吗 这是我的表单:(Fonction是Activite类中的一个属性,而etablisement的名称是etablisement类中的一个属性: <table id="tabmenu">
<table id="tabmenu">
<tr>
<td>Fonction :</td>
<td><form:input type="text" class="round default-width-input" path="fonction" /></td>
</tr>
<tr>
<td>Nom d'établissement :</td>
<td><form:input type="text" class="round default-width-input" path="noml"/></td>
</tr>
<tr>
<td>Ville :</td>
<td><form:input type="text" class="round default-width-input" path="villel"/></td>
</tr>
<tr>
<td>Délégation :</td>
<td><form:input type="text" class="round default-width-input" path="cd_reg" /></td>
</tr>
<tr>
<td>Date début :</td>
<td><form:input type="text" name="date" class="tcal" value="" path="dateAffect"/></td>
</tr>
<tr>
<td>Date fin :</td>
<td><form:input type="text" name="date" class="tcal" value="" path="dateAffect"/></td>
</tr>
<tr>
<td><input
class="button round blue image-right ic-right-arrow"
type="submit" value="Créer" /></td>
<td><input
class="button round blue image-right ic-right-arrow"
type="reset" value="Initialiser" /></td>
</tr>
</table>
</form:form>
Activite POJO:
public class Activite {
int code_act;
String cd_modaff;
String cd_etab;
String fonction;
int ppr;
String CINA;
String CINN;
public Activite() {
super();
}
//getters and setters ....
}
etablisement POJO
public class Etablissement {
String code_etab;
String code_gipe;
String noml;
String noma;
String cd_orgTutel;
String cd_reg;
String cd_prov;
String cd_com;
String cd_mil;
String cd_cauto;
String adressel;
String cp;
String villel;
//getters and sitters
}
我认为每个窗体只能有一个命令对象。如果有多个窗体,则只有您才能有多个命令对象。同一窗体是否需要多个命令对象?如果需要,我建议将所需属性合并到一个类中,因为它们属于同一窗体。我建议您先尝试。我尝试一下它不起作用,所以我真的需要一个解决方案,因为我不能在每个页面中一次只使用一个类,我需要manay对象类,而且不可能通过@modeldattribute提供它们。您可以将任意数量的
@modeldattribute
放入表单标记中,但我怀疑您是否可以在表单标记中包含许多commandName
。有一些解决方法。告诉我们som是的,例如commandName的问题,请参见上面的代码。您必须使用普通的html
,并使用完整的模型属性描述,例如${agent.property}
,我在这个解决方案中认为,但是我必须尊重我的概念!我不能在我的类的digram中添加我没有的类
public class Etablissement {
String code_etab;
String code_gipe;
String noml;
String noma;
String cd_orgTutel;
String cd_reg;
String cd_prov;
String cd_com;
String cd_mil;
String cd_cauto;
String adressel;
String cp;
String villel;
//getters and sitters
}