Hibernate 如何设置组合框jsp的默认值
我想要设置默认值=${theObject2.countryId} 你可以用。只需比较Id并将其设置为选中(如果匹配) 示例代码:Hibernate 如何设置组合框jsp的默认值,hibernate,jsp,spring-mvc,combobox,Hibernate,Jsp,Spring Mvc,Combobox,我想要设置默认值=${theObject2.countryId} 你可以用。只需比较Id并将其设置为选中(如果匹配) 示例代码: <select id="locationCountry" style="padding-left: 2em"> <option value="">Country</option> <c:forEach items="${countrieDetail}" var="theObject"> &
<select id="locationCountry" style="padding-left: 2em">
<option value="">Country</option>
<c:forEach items="${countrieDetail}" var="theObject">
<option value="${theObject.countryId}" <c:if test="${theObject.countryId == theObject2.countryId }">selected</c:if>>
${theObject.countryName}
</option>
</c:forEach>
</select>
您不能在支持表单的模型属性中设置默认值吗?然后Spring将只渲染具有所述值的组件。为什么要渲染对象2?2是一个打字错误?看看这篇文章,同样的逻辑被用来使它更清楚。
<select id="locationCountry" style="padding-left: 2em">
<option value="">Country</option>
<c:forEach items="${countrieDetail}" var="theObject">
<option value="${theObject.countryId}" <c:if test="${theObject.countryId == theObject2.countryId }">selected</c:if>>
${theObject.countryName}
</option>
</c:forEach>
</select>