我搜索了几个例子,仍然没有得到。我正在将一个 GOOD 对象列表从控制器传递到 jsp 页面。试图循环列表对象,但它只重复显示一个元素。我应该用豆子吗?如果是,您能否为我的案例提供更具体的示例。
<c:if test="${not empty listGood}">
<c:forEach var="ob" varStatus="status" items="${listGood}">
<tr>
<td><c:out value="${ob.name}"/></td>
<td><c:out value="${ob.measure}"/></td>
<td><c:out value="${ob.quantity}"/></td>
<td><c:out value="${ob.price}"/></td>
</tr>
</c:forEach>
</c:if>
更新 这里是控制器:
@RequestMapping(value={"/supply"}, method=RequestMethod.POST)
public String consumptFormulate(Locale locale, Model model, @ModelAttribute ConsumptionForm cmd, HttpServletRequest request){
String[] s_str =cmd.getFromDate().split("/");
String normal_s = s_str[2]+"-"+s_str[0]+"-"+s_str[1];
String[] f_str = cmd.getToDate().split("/");
String normal_f = f_str[2]+"-"+f_str[0]+"-"+f_str[1];
List<Good> list = service.getGoods(normal_s,normal_f,cmd.getSocGoods(),cmd.getTradeObj());
List<ListGoodsForm> listg = new ArrayList<ListGoodsForm>();
org.jfree.data.xy.XYSeries series = new org.jfree.data.xy.XYSeries("За месяц:");
if(!list.isEmpty()){
lg=list;
ListGoodsForm listo = new ListGoodsForm();
java.util.Calendar ca = java.util.Calendar.getInstance();
for(Good g: list){
listo.setName(g.getName());
listo.setMeasure(g.getMeasure());
listo.setPrice(g.getPrice());
listo.setQuantity(g.getQuantity());
listg.add(listo);
java.util.Date date = g.getDates();
java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("MMMM");
ca.setTime(date);
int in = ca.get(java.util.Calendar.MONTH);
String month = format.format(date);
}
}
request.setAttribute("listGood",listg);
//model.addAttribute("listGood", listg);
model.addAttribute("GOODS", prepareDataList());
// model.add
model.addAttribute("COMPANY",sservice.getSupplierName());
model.addAttribute("consumptionForm", cmd);
return "supply";
}