[英]How to insert using generatedId in MyBatis?
當我嘗試向表中插入數據時,總是會收到一個Exception
說id
為NULL
。 這是代碼:
@Insert({
"insert into device (tag)",
"values (#{tag,jdbcType=VARCHAR})"
})
@Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
int insert(Device record);
我也嘗試添加
@SelectKey(before = true, keyColumn = "id",
keyProperty = "id",
resultType = Integer.class,
statement = "SELECT SCOPE_IDENTITY()")
但是仍然出現錯誤。 然后我運行sql( SELECT SCOPE_IDENTITY()
)並得到一個null。
環境是: MyBatis 3.4.0
, SQL Server 2008
, Spring-Boot
嘗試在@SelectKey批注中設置before=false
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.