Mybatis插入数据返回主键id(传入多个参数)

 dao层的代码

int insertSelective(User person,String db)

mapper里面采用的是$param1,$param2进行接收参数,其中User为对象,db是要查询的某个数据库。

我采用的是:

<insert id="insertSelective">

<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">

select last_insert_id()

</selectKey>

</insert>

网上是这么告诉你的吧!然后发现并没有用。还是返回不了。这时候你就再想了,可能是我这个id没有对应上,然后你修改了一下

keyProperty="User.id" ,发现他不识别User。然后你想:那我改成$param1.id总行了吧,发现还不行。这时候,注意看你的dao层传入的那个对象名称是什么,是person  那就person.id吧。 

猜你喜欢

转载自blog.csdn.net/Chen_leilei/article/details/109472110
今日推荐