Mysql mapper配置返回自动生成的主键

编程语言 0 1047
小小草
小小草 2021年6月27日 20:00 发表
摘要:mapper返回自动生成的主键,使用last_insert_id 方式


mapper返回自动生成的主键,参见红色部分配置。


<insert id="insert" parameterType="cn.niter.forum.model.Article">

<selectKey keyProperty="id" resultType="Long" order="AFTER">
select last_insert_id()
</selectKey>


insert into article (id, title, description,
html, markdown, article_type,
source, link, pub_date
)
values (#{id,jdbcType=BIGINT}, #{title,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR},
#{html,jdbcType=VARCHAR}, #{markdown,jdbcType=VARCHAR}, #{articleType,jdbcType=INTEGER},
#{source,jdbcType=VARCHAR}, #{link,jdbcType=VARCHAR}, #{pubDate,jdbcType=VARCHAR}
)
</insert>


点赞 0 收藏(0)    分享
相关标签: java
问题没解决?让chatGPT帮你作答 智能助手
0 个评论
  • 消灭零评论