mybatis的insert語句插入數(shù)據(jù)時的返回值的實現(xiàn)
mybatis的sql語句一般是配置在配置文件中,現(xiàn)先給出一個例子,
sqlMap.xml文件中的一條插入語句:
<insert parameterClass='xxx'> insert into A(a, b, c, d) VALUE (#a#, #b#, #c#, #d#)</insert>
以上的代碼片段只是最簡單的插入語句,上面這條SQL語句無論執(zhí)行結(jié)果是成功還是失敗,它的返回值都是null
如果想要在執(zhí)行插入之后得到某個非null的返回值,上面那條sql語句需要再加點‘料’:
<insert parameterClass='xxx'> insert into A(a, b, c, d) VALUE (#a#, #b#, #c#, #d#) <selectKey resultClass='java.lang.Integer' keyProperty='id' > SELECT @@IDENTITY AS ID </selectKey></insert>
這樣寫的話當插入一條數(shù)據(jù)的時候,該插入操作的返回值就是剛剛插入的 那條記錄的主鍵值。
到此這篇關(guān)于mybatis的insert語句插入數(shù)據(jù)時的返回值的實現(xiàn)的文章就介紹到這了,更多相關(guān)mybatis insert返回值內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
