有时候我们需要mybatis获取insert 后的id,现有两种解决方案

方案一:

<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
      SELECT LAST_INSERT_ID()
    </selectKey>

方案二:

<insert id="insert" parameterType="com.xxx" useGeneratedKeys="true" keyProperty="id">

再强调一下,AFTER     BEFORE必须大写

参考地址:https://blog.csdn.net/hehuihh/article/details/82800739