共计 542 个字符,预计需要花费 2 分钟才能阅读完成。
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>
EL 表达式三木运算符格式:
${要判断的条件 ? 判断结果为 true 时的操作 : 判断结果为 false 时的操作}
正文完