el表达式 多条件判断

1.情景展示

  ACCESS_ID == 'APP1039' 且 CARDTYPE == 99进入条件体,否则走另外的条件体 

2.错误用法

<   c:when test="${model.personInfo.ACCESS_ID == 'APP1039'} && ${model.personInfo.CARDTYPE == 99}">
    <   div >页面展示    

3.正确方法

  方法一

<   c:choose >
    <   c:when test="${model.personInfo.ACCESS_ID == 'APP1039' && model.personInfo.CARDTYPE == 99}">
        <   div >页面展示1    
    
    <   c:otherwise >
        <   div >页面展示2    
    

  方法二

<   c:if test="${model.personInfo.ACCESS_ID == 'APP1039' && model.personInfo.CARDTYPE == 99}">
    <   div >页面展示1    

<   c:if test="${model.personInfo.ACCESS_ID != 'APP1039' || model.personInfo.CARDTYPE != 99}">
    <   div >页面展示2    
   

4.小结

  核心标签库c没有 if else 的条件判断,可以使用c:when和c:otherwise代替;

  使用c:when标签时,该标签体外必须声明c:choose标签;

  多条件判断符号"&&"和"||",必须在"${}"内;

  判断字符串是否相等,字符串需要加单引号'。

2023年7月20日15:47:03

5.补充说明

非空判断

方式一

<c:if test="${not empty model.zb[0].idno}">
    idno的值不为空'',也不为null
</c:if>

<c:if test="${!empty model.zb[0].idno}">
    idno的值不为空'',也不为null
</c:if>

方式二

<c:if test="${model.zb[0].idno != '' && model.zb[0].idno != null}">
    idno的值不为空'',也不为null
</c:if>

为空判断

同样地,为空判断也有两种实现方式

方式一

<c:if test="${empty model.zb[0].idno}">
    idno的值为null,或者为空
</c:if>

方式二

<c:if test="${model.zb[0].idno == '' || model.zb[0].idno == null}">
    idno的值为空'',或为null
</c:if>

 

写在最后

  哪位大佬如若发现文章存在纰漏之处或需要补充更多内容,欢迎留言!!!

 相关推荐:

posted @ 2018-09-13 09:14  Marydon  阅读(2292)  评论(0编辑  收藏  举报