我想使用以下方法取回插入 MySql 数据库的最后一篇文章的 id sqlx
:
resultPost, err := shared.Dbmap.Exec("INSERT INTO post (user_id, description, link) VALUES (?, ?, ?)", userID, title, destPath)
if err != nil {
log.Println(err)
c.JSON(
http.StatusInternalServerError,
gin.H{"error": "internal server error"})
}
fmt.Println("resultPost is:", resultPost)
问题是resultPost
被打印为对象:
resultPost is: {0xc420242000 0xc4202403a0}
所以我想知道提取刚刚插入的行的id的正确方法是什么?