ibatis selectKey用法注意事项

在我们使用插入数据库时,大部门ID是自增长的,需要返回ID,然后再插入相关的关系表中。但是有时候同样也会抛出问题,比如以下场景:

  1. 开始使用int做为ID自增长,返回相关的主键值,但是后来改动,改为String类型,使用UUID赋值,但是在ibatis时,依然保留如下的配置:

  2.   <insert id="insertInternet" parameterClass="dmGroupDO" >
        INSERT INTO dm_group(id,name,status,u_id,members)
         VALUES (#id#, #name#, #status#, #uId#, #members#)
          <selectKey keyProperty="id" resultClass="java.lang.String" >
          SELECT LAST_INSERT_ID() AS value
        </selectKey>
      </insert>


     结果,在返回bean对象插入后,再次调用这个bean的ID时,结果返回的变成数字,因为ibatis 会将查询出来的数字类型赋值到Bean的id字段中。

你可能感兴趣的:(ibatis selectKey用法注意事项)