一对多休眠,保存空值

时间:2012-09-24 14:39:08

标签: spring hibernate jstl

这是我的Jsp迭代列表的代码

<c:forEach items="${location.fEvents}" var="item" varStatus="loop">
                <tr><td><form:input path="fEvents[${loop.index}].hostName" size="30" maxlength="200"/></td>
                <td><form:input path="fEvents[${loop.index}].directory" size="30" maxlength="200"/></td>
                <td><form:input path="fEvents[${loop.index}].userName" size="20" maxlength="20"/></td>
                <td><form:input path="fEvents[${loop.index}].password" size="20" maxlength="20"/></td>
                </tr>
            </c:forEach>

我在控制器中的代码:

while (location.getfEvents().size() < 3) {
            FtpScanEvents f = new FtpScanEvents();
            f.setLocation(location);
            location.getfEvents().add(f);
        }   

每当有新条目时,我的jsp显示三个空行,如果用户在第一行输入数据,它应该只保存到数据库。但是,我的代码将另外两个空行保存为数据库的null。这是因为我使用spring绑定并迭代列表来显示值(JSP Code)。

任何避免这种情况的建议!

提前致谢!

1 个答案:

答案 0 :(得分:0)

在插入数据库之前,检查字段是否为null和空。