usermapper.xml <insert id="insert" parameterType="app.models.User" keyProperty="id"> <selectKey keyProperty="id" order="AFTER" resultType="int"> SELECT LAST_INSERT_ID() </selectKey> insert into users (id, name, email, password) values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}) </insert>
User user = new User("zn", "[email protected]", "12345674233"); userMapper.insert(user); System.out.println(user.getId());