Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring-MVC将对象从foreach传递到另一个控制器_Spring_Jsp_Spring Mvc_Spring Annotations - Fatal编程技术网

Spring-MVC将对象从foreach传递到另一个控制器

Spring-MVC将对象从foreach传递到另一个控制器,spring,jsp,spring-mvc,spring-annotations,Spring,Jsp,Spring Mvc,Spring Annotations,我有一个由forEach-spring标记显示的对象列表。以下是jsp的代码: <c:forEach items="${liste_fiche}" var="fiche"> <div class="card blue-grey darken-1"> <form:form action="display_fiche" method="post" commandName="fiche" varSta

我有一个由forEach-spring标记显示的对象列表。以下是jsp的代码:

<c:forEach items="${liste_fiche}" var="fiche">
                <div class="card blue-grey darken-1">
                    <form:form action="display_fiche" method="post" commandName="fiche" varStatus="status">
                        <div class="card-content white-text">
                            <span class="card-title">Fiche numéro ${fiche.id}</span>
                        <p>reference de la fiche : ${fiche.ref_fiche}</p>
                        <p>type de fiche : ${fiche.typeFiche}</p>
                        </div>
                        <div class="card-action">

                            <button type="submit" action="display_fiche"
                                class="waves-effect waves-light btn">Afficher la fiche</button>

                        </div>
                    </form:form>
                </div>
    </c:forEach>
我不知道这是否是一个好方法,因为它不起作用。我总是得到一个fiche.getId的“0”。如果不可能,我如何只传递fiche.id元素

和控制器

@RequestMapping(value="/display_fiche/{id}", method = RequestMethod.GET)
private ModelAndView displayFiche(@PathVariable("id") Long id, ModelMap modelMap) {
    System.out.println("Fiche séléctionnée : " + id);
    return model;
}

谢谢你的回答,我想我会使用你的第二个解决方案。事实上,带有a href的GET请求似乎对我有好处:
<button type="submit" action="display_fiche" class="waves-effect waves-light btn">
Afficher la fiche
</button>
<a href="/display_fiche/${fiche.id}" class="waves-effect waves-light btn">
Afficher la fiche
</a>
@RequestMapping(value="/display_fiche/{id}", method = RequestMethod.GET)
private ModelAndView displayFiche(@PathVariable("id") Long id, ModelMap modelMap) {
    System.out.println("Fiche séléctionnée : " + id);
    return model;
}