<insert id="insertAndGetId" useGeneratedKeys="true" keyProperty="userId" parameterType="com.chenzhou.mybatis.User">insert into user(userName,password,comment)values(#{userName},#{password},#{comment})</insert>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());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());输出:插入前主键为:0插入后主键为:15