犯了个低级错误:mybatis中在select标签中用了update语句

概述


昨晚想使用类似下面的语句防并发问题:

 update xxxxx set state= 1
 where id = 1 and state= 0

这样万一有线程并发修改state,那么只有一个线程能拿到大于0的影响行数。谁知一调用就报如下错误:

attempted to return null from a method with a primitive return type (int)

定位了半天,原来是在select标签中用了update语句:

  <select id="updateUserIsAllowDrawStatus">
         update xxxxx set state= 1
          where id = 1 and state= 0
  </select >

应该要改成:

<update id="updateUserIsAllowDrawStatus">
         update xxxxx set state= 1
          where id = 1 and state= 0
</update >

用博客记录一下,曾经犯过的这个低级错误。

猜你喜欢

转载自blog.csdn.net/linsongbin1/article/details/80372201