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

EL表達式中使用三目運算符:spa

    下面的例子的實現的功能是,若是questionType表中遍歷出來的questionTypeId等於question對象中保存的questionTypeId,那麼就在遍歷出來的對應的questionType選項中添加selected屬性。code

​​
clipboard.png

<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>

EL表達式三木運算符格式:對象

${ 要判斷的條件 ? 判斷結果爲true時的操做 : 判斷結果爲false時的操做}
相關文章
相關標籤/搜索