EL表達式中使用三目運算符判斷

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>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章