我的Batis删除查询返回类型不一致

时间:2014-05-02 02:45:54

标签: spring-mvc mybatis

我使用spring-mybatis进行删除查询

这就是我的通话方式

if(mapper.deleteSomething(id))
{

.....
}

在我的映射器中我有

<delete id = "deleteSomething">
delete from table where id = #{id}
</delete>

但是我注意到,如果删除成功,返回类型并不总是如此。有时它返回true,有时返回false,但记录总是在db。

中删除

我做错了什么?

1 个答案:

答案 0 :(得分:1)

以下是您需要做出的更改。

  1. 更改映射器接口方法

     public interface yourinterface{
       public int deleteSomething(<data type> id)
     }
    

    我在你的mapper文件中看到没有提到输入的参数类型,最好添加

  2. 条件更改

     int count =mapper.deleteSomething(id);
     if(count>0){
       System.out.println("Deleted "+ count +"records");
     }else{
       System.out.println("Delete failed");
     }
    
相关问题