EL表達式中使用三目運算符:
下面的例子的實現的功能是,如果questionType表中遍歷出來的questionTypeId等於question對象中保存的questionTypeId,那麼就在遍歷出來的對應的questionType選項中添加selected屬性。
<select name="questionTypeId">
<c:forEach items="${questionTypes }" var="questionType">
<option value="${questionType.questionTypeId }"
${questionType.questionTypeId == question.questionType.questionTypeId ? 'selected' : ''}>
${questionType.questionTypeName }
</option>
<!-- <option>員工手冊</option> -->
</c:forEach>
</select>