mybatis MySQL返回插入的主键ID,oracle不行
<insertid=“doSomething"parameterType="map"useGeneratedKeys="true"keyProperty=“yourId">
...
</insert>
或
<insert id=“doSomething" parameterType=“com.xx.yy.zz.YourClass" useGeneratedKeys="true" keyProperty=“yourId">
...
</insert>
直接用插入对象的ID来接收就行
User user = new User(); user.setUserName("chenzhou"); user.setPassword("xxxx"); user.setComment("测试插入数据返回主键功能"); System.out.println("插入前主键为:"+user.getUserId()); userDao.insertAndGetId(user);//插入操作 System.out.println("插入后主键为:"+user.getUserId());