您好,登錄后才能下訂單哦!
在MyBatis中,可以通過使用useGeneratedKeys
配置來實(shí)現(xiàn)Integer類型的自動填充。具體步驟如下:
insert
語句中,設(shè)置useGeneratedKeys
為true,并指定keyProperty
為你想要自動填充的字段名,如下所示:<insert id="insertUser" parameterType="User" useGeneratedKeys="true" keyProperty="id">
insert into user (name, age) values (#{name}, #{age})
</insert>
keyProperty
相同的字段,并使用對應(yīng)的setter和getter方法,如下所示:public class User {
private Integer id;
private String name;
private Integer age;
// getter and setter method for id
// getter and setter method for name
// getter and setter method for age
}
這樣,在執(zhí)行插入操作后,MyBatis會自動將生成的主鍵值填充到id
字段中。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。