【问题标题】:Submit complexe object to controller using @ModelAttribute with spring mvc使用 @ModelAttribute 和 spring mvc 将复杂对象提交给控制器
【发布时间】:2013-06-28 10:36:00
【问题描述】:

我使用带有 jsp/jstl 的 spring mvc 3.1.0 请问如何在spring mvc中使用@ModelAttribute进行转换

我想从我的jsp页面向控制器提交一个对象,我的对象包含我的类中一个对象字段的选择标签,该标签总是以空值提交。

我的对象:

UorgVO.java

public class UorgVO {

private String nom;
private String nomAbrege;
private UorgVO refUniteOrganisParent ;
//getters&Setters..
}

还有我的jsp页面:

<form:form method="post" action="saveUorg.html"  modelAttribute="uorg" >
<table >
<tr>
    <th>Nom</th>
    <th>Nom abregé</th>
    <th>Unité père</th>
</tr>
<tr>
    <td><input  type="text" path="nom" name="nom"/></td>
    <td><input  type="text" path="nomAbrege" name="nomAbrege"/></td>
    <td><select id="refUniteOrganisParent" name="refUniteOrganisParent" path="refUniteOrganisParent">
        <option  value="null"> --- </option> 
      <c:forEach items="${listeuos}" var="uorgg" varStatus="status" >
        <option value="${uorgg}">${uorgg} </option> 
      </c:forEach>
        </select>
    </td>
</tr>
</table> 
<input type="submit" value="Enregistrer uorg"  <BQ>  <a href="recherche_uorg.html">   Annuler</a>    
</form:form>

我的控制器是:

    @RequestMapping(value ="/saveUorg", method = RequestMethod.POST)
    public ModelAndView saveUorg(@ModelAttribute("uorg") UorgVO uorg,BindingResult result){

    System.out.println("contenu du nom de l'UO est :" +uorg.getRefUniteOrganisParent());


    return new ModelAndView("uorg_recherche");  
    }   

打印出来的值为空

提前感谢您的帮助

【问题讨论】:

    标签: jsp spring-mvc jstl modelattribute


    【解决方案1】:

    我猜您将无法使用这些表单绑定嵌套对象。您可能想要查看的是 Spring Binding Form。参考here

    【讨论】:

    • 我试过但没有结果,我想我必须使用转换器但我不知道我是如何尝试多次但它不起作用..
    • 我以前做过这种绑定。我相信这应该有效。您可以使用弹簧绑定标签发布代码
    • 弹簧绑定标签在我的代码中不起作用,它会留下一个错误,所以我只使用模型属性。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-23
    • 2017-01-08
    • 2014-10-20
    • 2016-11-18
    • 2015-02-13
    • 1970-01-01
    • 2012-08-12
    相关资源
    最近更新 更多