這篇文章主要介紹了Mybatis如何插入一條或批量插入返回帶有自增長主鍵記錄,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
創(chuàng)新互聯(lián)是專業(yè)的海勃灣網(wǎng)站建設(shè)公司,海勃灣接單;提供成都網(wǎng)站設(shè)計、網(wǎng)站制作,網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進行海勃灣網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團隊,希望更多企業(yè)前來合作!首先講一下, 插入一條記錄返回主鍵的 Mybatis 版本要求低點,而批量插入返回帶主鍵的 需要升級到3.3.1版本,3.3.0之前的都不行。
<dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>3.3.1</version> </dependency>
1.MySQL
<insert id="insertByBatch" useGeneratedKeys="true" keyProperty="id" parameterType="java.util.List"> insert into test (sblsh, xh, jsjg, is_success, is_display, gmt_create, gmt_modify, create_user) values <foreach collection="list" item="item" index="index" separator=","> ( #{item.sblsh,jdbcType=BIGINT}, #{item.xh,jdbcType=CHAR}, #{item.jsjg,jdbcType=BIGINT}, #{item.isSuccess,jdbcType=TINYINT}, #{item.isDisplay,jdbcType=TINYINT}, SYSDATE(), SYSDATE(), #{item.createUser,jdbcType=VARCHAR}) </foreach> </insert>
單條和多條 使用都是一樣的, 加入useGeneratedKeys="true" keyProperty="主鍵字段"
2.Oracle
<insert id="insertBatch"> <selectKey keyProperty="id" resultType="Long" order="BEFORE"> select test.nextval as id from dual </selectKey> insert into test (id,value,gmt_create,gmt_modified) select test.nextval, A.* FROM ( <foreach collection="list" item="item" index="index" separator="union all"> select #{item.value,jdbcType=VARCHAR}, #{item.gmtCreate,jdbcType=DATE}, #{item.gmtModified,jdbcType=DATE} from dual </foreach> ) A </insert>
感謝你能夠認真閱讀完這篇文章,希望小編分享的“Mybatis如何插入一條或批量插入返回帶有自增長主鍵記錄”這篇文章對大家有幫助,同時也希望大家多多支持創(chuàng)新互聯(lián),關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,更多相關(guān)知識等著你來學習!
本文標題:Mybatis如何插入一條或批量插入返回帶有自增長主鍵記錄-創(chuàng)新互聯(lián)
標題網(wǎng)址:http://aaarwkj.com/article10/ccosdo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供動態(tài)網(wǎng)站、面包屑導航、網(wǎng)站內(nèi)鏈、建站公司、品牌網(wǎng)站設(shè)計、電子商務(wù)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容