<insert id="insertAndGetId" useGeneratedKeys="true" keyProperty="userId" parameterType="com.chenzhou.mybatis.User">
insert into user(userName,password,comment)
values(#{userName},#{password},#{comment})
</insert> 插入后,直接通过userId这个property存主键
mybatis insert with id return
最新推荐文章于 2025-06-06 20:33:41 发布
本文详细介绍了如何使用MyBatis的XML映射文件进行SQL操作,特别是如何通过设置`useGeneratedKeys`和`keyProperty`属性来实现通过userId存储主键并插入数据的过程。通过具体的例子,展示了如何在数据插入后获取自动生成的主键值。
6748

被折叠的 条评论
为什么被折叠?



