jsp获取一个对象和list对象

时间:2022-07-25 21:09:12

DiscHd ks = DiscHdService.getDiscHdByID(code);
model.addAttribute("ks", ks);

如果传的是对象,则jsp页面直接用"${ks.DValue}"得到值。

List<DiscDet> discDets=discDetService.getDiscDetByCode(code);
// System.out.println("discDets的数据为:
"+discDets.get(0).getDValue()+","+discDets.get(0).getType()+","+discDets.get(0).getDOpen()+","+discDets.get(0).getDetail());
for(int i=0;i<discDets.size();i++){System.out.println(discDets.get(i).getType().equals("DHDC"));
if(discDets.get(i).getType().equals("DHDC")){
System.out.println(discDets.get(i).getType());
List<DiscDet> DHDC=new ArrayList<DiscDet>();
DHDC.add(discDets.get(i));
System.out.println(DHDC.get(0).getDValue()+"@@@@@@@@@@@@");
model.addAttribute("DHDC",DHDC);
}
}

如果传的是list,则jsp页面<c:forEach>得到值

<c:forEach items="${DHDC}" var="DHDC">
<input type="hidden" id="sss" name="sss" value="${DHDC.DValue}"/>
</c:forEach>