把stus注释掉


正常访问就会报错

第20行 这里的stus为空,所以造成了这个错误。

不为空用双问号来判断

<#if stus??>
<#list stus as stu>
<tr>
<td>${stu_index+1}</td>
<td <#if stu.name=="小明">style="background-color:cornflowerblue"</#if>>${stu.name}</td>
<td>${stu.age}</td>
<td <#if (stu.money gt 300)>style="background-color: cornflowerblue"</#if>${stu.money}</td>
<#--<td>${stu.birthday}</td>-->
</tr>
</#list>
</#if>

 





加了空值 的判断就不报错了。

默认值


把stu1设置为空

36行代码从报错

第36行代码

可以用非空判断的方式

 

<#if stuMap?? && stuMap.stu1??>
姓名:${stuMap['stu1'].name}<br/>
年龄:${stuMap['stu1'].age}<br/>
姓名:${stuMap.stu1.name}<br/>
年龄:${stuMap.stu1.age}<br/>
</#if>

 



缺省

姓名:${(stuMap['stu1'].name)!''}<br/>
年龄:${(stuMap['stu1'].age)!''}<br/>
姓名:${(stuMap.stu1.name)!''}<br/>
年龄:${(stuMap.stu1.age)!''}<br/>

 





姓名:${(stuMap['stu1'].name)!''}<br/>
年龄:${(stuMap['stu1'].age)!''}<br/>
姓名:${(stuMap.stu1.name)!''}<br/>
年龄:${(stuMap.stu1.age)!''}<br/>

 

相关文章:

  • 2022-01-15
  • 2022-01-09
  • 2021-06-02
  • 2021-06-15
  • 2022-01-07
  • 2022-02-15
  • 2021-12-23
  • 2021-09-22
猜你喜欢
  • 2021-12-13
  • 2021-09-17
  • 2022-01-18
  • 2021-11-24
  • 2021-11-03
  • 2021-06-16
  • 2021-08-16
相关资源
相似解决方案