ibatis获取数据插入mysql时的自增字段

rikimura2 rikimura2 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
RT,ibatis获取数据插入mysql时的自增字段id,id是没有任何意义的自增主键,xml代码见下面,然后我在java里面用dao调用:Integer id = resCollDao.addMetadata(mData);System.out.println(id);,然后得到的id值始终为1,但是控制台能看到已经select出来的数据,是说这样select出来的数据不能直接在java里接吗?

<insert id="addMetadata" parameterType="MetadataBean"
useGeneratedKeys="true" keyProperty="id">
insert into cfsdc_metadata(
language,
contacterName,
unit,
position,
telephone,
fax,
address,
city,
province,
zip,
country,
email,
workhour,
createdTime
) values (
#{language},
#{contacterName},
#{unit},
#{position},
#{telephone},
#{fax},
#{address},
#{city},
#{province},
#{zip},
#{country},
#{email},
#{workhour},
#{createdTime}
)
<selectKey resultType="int" keyProperty="id" >
select @@IDENTITY as id
</selectKey>
</insert>


12-11-05@18:42:14 DEBUG - ooo Connection Opened
12-11-05@18:42:14 DEBUG - ==> Executing: insert into cfsdc_metadata( language, contacterName, unit, position, telephone, fax, address, city, province, zip, country, email, workhour, createdTime ) values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
12-11-05@18:42:14 DEBUG - ==> Parameters: null, null, null, null, null, null, null, null, null, null, null, null, null, null
12-11-05@18:42:14 DEBUG - ==> Executing: select @@IDENTITY as id
12-11-05@18:42:14 DEBUG - ==> Parameters:
12-11-05@18:42:14 DEBUG - <== Columns: id
12-11-05@18:42:14 DEBUG - <== Row: 15
12-11-05@18:42:14 DEBUG - xxx Connection Closed
1
...全文

相关推荐

评论 8
收藏 已收藏
分享
返回顶部
rikimura2
Web 开发 81,108 成员 341,721 内容