mirror of
https://github.com/CarmJos/EasySQL.git
synced 2026-06-04 15:28:20 +08:00
添加一个同步插入返回ID的方法
This commit is contained in:
@@ -92,9 +92,22 @@ public class EasySQLDemo {
|
||||
.setKeyIndex(1) // 设定自增主键的index,将会在后续返回自增主键
|
||||
.execute((exception, action) -> {
|
||||
// 处理异常
|
||||
System.out.println(action);
|
||||
|
||||
System.out.println("#" + action.getShortID() + " -> " + action.getSQLContent());
|
||||
exception.printStackTrace();
|
||||
});
|
||||
|
||||
try {
|
||||
Integer userID = sqlManager.createInsert("users")
|
||||
.setColumnNames("username", "phone", "email", "registerTime")
|
||||
.setParams("CarmJos", "18888888888", "carm@carm.cc", TimeDateUtils.getCurrentTime())
|
||||
.setKeyIndex(1) // 设定自增主键的index,将会在后续返回自增主键
|
||||
.execute();
|
||||
|
||||
System.out.println("新用户的ID为 " + userID);
|
||||
|
||||
} catch (SQLException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user