比较两个对象discs、outlets中的元素是否相等。相同则相应的checkbox为checked
<div id="div1" name="div1" class="area" style="position:relative;">
<c:if test="${!empty outlets}"> <dl> <c:forEach items="${outlets}" var="outlet"> <c:set var="has" value="0" ></c:set> <dd> <c:if test="${!empty discs}"> <c:forEach items="${discs}" var="discs"> <c:if test="${discs.outlet==outlet.outlet}"> <c:set var="has" value="1"></c:set> </c:if> </c:forEach> </c:if> <input id="outlet" type="checkbox" value="${outlet.outlet }" id="${outlet.outlet }" name="outlet" <c:if test="${has==1}">checked="checked"</c:if> /> <label for="${outlet.outlet }">${outlet.outlet }-${outlet.desc1 }</label> </dd> </c:forEach> </dl> </c:if> </div>
Controller传输discs,outlets
List<DiscS> discs=discSService.getDiscSByCode(code);
/* System.out.println(discs.get(0).getOutlet()+"@@"); System.out.println(discs.get(1).getOutlet()+"!!"); System.out.println(discs.get(2).getOutlet()+"##");*/ model.addAttribute("discs",discs); List<Outlet> outlets = outletService.getOutlets(); /*System.out.println(outlets.get(0).getOutlet()); System.out.println(outlets.get(1).getOutlet()); System.out.println(outlets.get(2).getOutlet());*/ model.addAttribute("outlets", outlets);