**
1,描述
**
<c:if>标签判断表达式的值,如果表达式的值为 true 则执行其主体内容。
**
2,语法
**
<c:if test="<boolean>" var="<string>" scope="<string>">
...
</c:if>
**
3,应用:
**
我主要用来根据不同的用户隐藏系统部分功能,比如,
非admin用户,不能看到【数据模型生成】按钮,自然也不能操作该功能
代码:
<c:if test="${sessionUserEntity.lname=='Admin'||sessionUserEntity.lname=='admin'}">
<button class="layui-btn layui-btn-xs layui-btn-primary " style="margin-left: 15px;width: 90px;" data-type="reload" id="model" onclick="model()">数据模型生成</button>
</c:if>
**
4,注意
**
在使用<c:if> 标签的时候,需要在文件头部引入标签库
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
5,扩展
if____else____
语法:
<c:choose>
<c:when test="<boolean>">
// 执行1
</c:when>
<c:otherwise>
// 执行2
</c:otherwise>
</c:choose>
应用:
<label style="width: 70px">模型类型:</label>
<div>
<select id="modeltype" name="modeltype" multiple="multiple" lay-filter="modeltypechange" style="width: 200px">
<c:forEach items="${modellist}" var="y" varStatus="status">
<c:choose>
<c:when test="${y.modeltypename=='基础表单'}">
<option value="${y.modeltypename}" >${y.modeltypename}</option>
</c:when>
<c:otherwise>
<option value="${y.modeltypename}" selected>${y.modeltypename}</option>
</c:otherwise>
</c:choose>
</c:forEach>
</select>
</div>
if____else if____else
语法:
<c:choose>
<c:when test="<boolean>">
// 执行1
</c:when>
<c:when test="<boolean>">
// 执行2
</c:when>
<c:otherwise>
// 执行3
</c:otherwise>
</c:choose>
应用:
<select id="modeltype" name="modeltype" multiple="multiple" lay-filter="modeltypechange" style="width: 200px">
<c:forEach items="${modellist}" var="y" varStatus="status">
<c:choose>
<c:when test="${y.modeltypename=='基础表单'}">
<option value="${y.modeltypename}" >${y.modeltypename}</option>
</c:when>
<c:when test="${y.modeltypename=='科室表单'}">
<option value="${y.modeltypename}" >${y.modeltypename}</option>
</c:when>
<c:otherwise>
<option value="${y.modeltypename}" selected>${y.modeltypename}</option>
</c:otherwise>
</c:choose>
</c:forEach>
</select>