当前位置: 代码迷 >> J2EE >> mybatis返回自增id,该怎么解决
  详细解决方案

mybatis返回自增id,该怎么解决

热度:41   发布时间:2016-04-17 23:15:14.0
mybatis返回自增id
我在用mybatis返回自增id时一直返回1,好像是只返回了插入条数,没返回我需要的自增id。请帮我看下问题出在哪里?
这是insert语句,数据库用的是mysql
<insert id="insertIndentid" parameterType="java.util.HashMap" useGeneratedKeys="true">
insert into indentid (user_name,total_int_price,total_out_price,date) 
values(#{user_name},#{total_int_price},#{total_out_price},#{date})
<selectKey resultType="Long" order="AFTER" keyProperty="indentid_id">
SELECT LAST_INSERT_ID() AS indentid_id
</selectKey>
</insert>
Dao接口
public Integer insertIndentid(HashMap map);
Biz
Integer indentid_id = sailDao.insertIndentid((HashMap)map);
System.out.println(indentid_id);
控制台输出信息
[INFO]: class action.core.SailAction
1
返回值我试过int   java.lang.Integer等等,但是都是返回1。问题出在哪里呢?


来大神帮我看一下。


------解决思路----------------------
可以通过设置parameterType是对应表的对象类型,在执行完insert后,通过对象属性取值获取自增主键值
------解决思路----------------------
嗯,返回值都是1,那是添加成功记录,返回的ID在参数里面,map里取值
  相关解决方案