1

我想从存储在数据库中的表中永久删除一行,该表正在显示在 jsp 页面上。我有一个链接Delete(对于每一行),只需单击一下即可删除该行。

我的jsp代码是:

    <s:iterator value="topperList" >
      <tr>
         <td><s:property value="uid"/></td>
         <td><s:property value="name"/></td>
         <td><s:property value="password"/></td>
         <td><s:property value="sex" /></td>
         <td><s:property value="age" /></td>
         <td><s:property value="city" /></td>
         <td><s:property value="abuse" /></td>
         <td><s:property value="lastlogin" /></td>
         <td><s:property value="points" /></td>
         <td><s:property value="joined" /></td>
         <td><s:property value="email" /></td>
         <s:url id="url" action="delete" >
           <s:param name="uid"><s:property value="uid" /></s:param>
         </s:url>
         <td><s:a href="%{url}">Delete</s:a></td>
      </tr> 
  </s:iterator>

我在动作类中的代码是:

private Integer uid;

public Integer getUid() {
    return uid;
}

public void setUid(Integer uid) {
    this.uid = uid;
}
public String delete() {
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        Users user = (Users) session.load(Users.class, this.getUid());
        if (null != user) {
            session.delete(user);
        }
        session.getTransaction().commit();
           return SUCCESS;
    }

struts.xml 中的操作代码:

<action name="delete" class="com.rambo.action.FindToppers" method="delete" >
        <result name="success">buser.jsp</result>
    </action>

但我得到了错误:

org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [beans.Users#0]

我已经看到 table 中有一个适当的行USERS with uid=56。但它显示没有具有标识符的行存在。但是我没有收到任何服务器错误日志。有人可以指出可能是什么问题。

4

2 回答 2

0

私人整数 cid;

这应该是公开的,您可以将其更改为 int

于 2012-07-15T11:13:31.270 回答
0

我想我看到了问题。问题是动作中的属性cidnull(你可以做 a System.out.println(cid))。如果null打印了可能你将不得不用 . 捕获 url 参数ParameterAware

于 2012-07-15T11:44:41.833 回答