0
我是新來的Ibatis。如何使用Ibatis生成序列號並將該數字插入到MySQL表中?序列號應以1000開頭,以便它可以用作表中的主鍵。我使用spring,ibatis和mysql。Ibatis序列號的產生
我是新來的Ibatis。如何使用Ibatis生成序列號並將該數字插入到MySQL表中?序列號應以1000開頭,以便它可以用作表中的主鍵。我使用spring,ibatis和mysql。Ibatis序列號的產生
由於iBatis自2010年以來一直死亡,我假定MyBatis的使用。隨着MyBatis you can use these annotations to insert and retrieve primary key from DB and map both to a interface:
@Insert("insert into table2 (name) values(#{name})")
@SelectKey(statement="call identity()", keyProperty="nameId", before=false, resultType=int.class)
int insertTable2(Name name);
您應該切換到MyBatis的,因爲iBatis的是在2010年搬到了閣樓:http://attic.apache.org/projects/ibatis.html – luboskrnac
你試過一些iBatis的文檔嗎? Java教程的第20頁提到了如何使用Oracle和SQL服務器來創建序列號。應該很容易切換到MySQL。 https://ibatis.apache.org/docs/java/pdf/iBATIS-SqlMaps-2_en.pdf – Barett
「序列號**應以1000開頭,以便它可以用作表中的主鍵**」 - 即使你的序列從1開始,你仍然可以使用它作爲主鍵。 – Bikku