<insert id="insertUser" useGeneratedKeys="true" keyProperty="id" parameterType="com.sqxinxibu.neikanhoutai.entity.AdminUser" > insert into user (id, name, salt, headUrl,password,role) values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{salt,jdbcType=VARCHAR}, #{headUrl,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, #{role,jdbcType=VARCHAR}) </insert>
其中加上 useGeneratedKeys=”true” keyProperty=“ID”
他在插入后, 会自动把插入的数据生成的ID
塞入到你这个 keyProperty 后面设置的 id这个参数里面。
执行之后 你直接取id 的值就好了。
如果接收的是 实体类的话, 当然实体类里面就要定义id 这个属性了