【发布时间】:2015-02-16 01:41:18
【问题描述】:
在设置 HTML 之前,我曾经使用 JSTL 来测试 null 的值。但我最终得到了一个冗长的代码片段:
<c:choose>
<c:when test="${data == null}">
<input type ='text'>
<input type ='text'>
<input type ='text'>
<input type ='text'>
<input type ='text'>
</c:when>
<c:otherwise>
<input type ='text' value= "${data.getAttribute1()}">
<input type ='text' value= "${data.getAttribute2()}">
<input type ='text' value= "${data.getAttribute3()}">
<input type ='text' value= "${data.getAttribute4()}">
<input type ='text' value= "${data.getAttribute5()}">
</c:otherwise>
</c:choose>
但是当我不使用 JSTL 时,我仍然得到正确的 HTML 页面而没有任何错误,并且当页面没有调用控制器时,似乎没有任何问题。代码如下:
<input type ='text' value= "${data.getAttribute1()}">
<input type ='text' value= "${data.getAttribute2()}">
<input type ='text' value= "${data.getAttribute3()}">
<input type ='text' value= "${data.getAttribute4()}">
<input type ='text' value= "${data.getAttribute5()}">
我只是浪费代码行来检查null吗?
【问题讨论】: