最近在改程序,原本是插入数据,每100条批处理一次,但是现在需要返回插入数据的id,不知道该怎么改实现这个功能

解决方案 »

  1.   

     <insert id="insertSelective" parameterType="com.grandstream.website.domain.Sys_Operator" useGeneratedKeys="true" keyProperty="sysid"> </insert>
    在ibatise sql语句配置为文件加如上红色文字属性就可以了 当你插入数据库 那个对象的ID被自动返回
      

  2.   

     <insert id="insertSelective" parameterType="你的bean"
    useGeneratedKeys="true" keyProperty="sysid"> </insert>
      

  3.   

    如果是批处理的怎么返回
    int batch = 0;
    for (int i = 0; i < list.size(); i++) {
    ProductBean product = list.get(i); Long id = (Long) executor.insert(
    "Product.insertProductBatch", product);
    batch++;
    if (batch == 100) {
    executor.executeBatch();
    batch = 0;
    }
    }
    executor.executeBatch();
    return list;
      

  4.   

    批处理不还是 一条一条SQL语句处理的吧 insert(domain实体类) 每次调用好那个插入语句 id自动返回了啊