`

Mybatis insert 插入记录后自动返回主键(Mybatis3.x)

 
阅读更多
<insert id="insertReceipt" parameterType="Receipt" useGeneratedKeys="true" keyProperty="id"
        insert into tb_receipt (name,from_storage_code,to_storage_code,description,type_id,code,batch_number)  
        values ( #{name},#{fromStorageCode},#{toStorageCode}, 
        <choose> 
            <when test="description!=null"> 
                #{description} 
            </when> 
            <otherwise> 
                '' 
            </otherwise> 
        </choose>, 
        <choose> 
            <when test="typeId!=null"> 
                #{typeId} 
            </when> 
            <otherwise> 
                0 
            </otherwise> 
        </choose>, 
        <choose> 
            <when test="code!=null"> 
                #{code} 
            </when> 
            <otherwise> 
                '' 
            </otherwise> 
        </choose>, 
        #{batchNumber} ) 
        <selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="id" > 
          SELECT LAST_INSERT_ID() 
        </selectKey> 
    </insert> 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics