Spring-MVC将对象从foreach传递到另一个控制器
我有一个由forEach-spring标记显示的对象列表。以下是jsp的代码: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
<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;
}