mybatis批量插入,怎么返回生成的自增主键


mybatis映射文件如下:

INSERT INTO tbl_data_report
(query_condition, website_id,
reseller_name, receivableIncome_flight, fee_flight,
realIncome_flight, payableAcount_flight, profit_flight,
receivableIncome_ticket, fee_ticket, realIncome_ticket,
payableAcount_ticket, profit_ticket, commission_ticket,
realIncome_hotel, receivableIncome_count, realIncome_count,
fee_count, payableAcount_count, commission_count,
profit_count, settlementTime, teller,
finance, note)
values

(
#{element.queryCondition,jdbcType=VARCHAR}, #{element.websiteId,jdbcType=INTEGER},
#{element.resellerName,jdbcType=VARCHAR}, #{element.receivableincomeFlight,jdbcType=DOUBLE}, #{element.feeFlight,jdbcType=DOUBLE},
#{element.realincomeFlight,jdbcType=DOUBLE}, #{element.payableacountFlight,jdbcType=DOUBLE}, #{element.profitFlight,jdbcType=DOUBLE},
#{element.receivableincomeTicket,jdbcType=DOUBLE}, #{element.feeTicket,jdbcType=DOUBLE}, #{element.realincomeTicket,jdbcType=DOUBLE},
#{element.payableacountTicket,jdbcType=DOUBLE}, #{element.profitTicket,jdbcType=DOUBLE}, #{element.commissionTicket,jdbcType=DOUBLE},
#{element.realincomeHotel,jdbcType=DOUBLE}, #{element.receivableincomeCount,jdbcType=DOUBLE}, #{element.realincomeCount,jdbcType=DOUBLE},
#{element.feeCount,jdbcType=DOUBLE}, #{element.payableacountCount,jdbcType=DOUBLE}, #{element.commissionCount,jdbcType=DOUBLE},
#{element.profitCount,jdbcType=DOUBLE}, #{element.settlementtime,jdbcType=TIMESTAMP}, #{element.teller,jdbcType=VARCHAR},
#{element.finance,jdbcType=VARCHAR}, #{element.note,jdbcType=VARCHAR}
)


报错如下:
org.apache.ibatis.binding.BindingException: Parameter 'id' not found. Available parameters are [list]

求大神解答

mybatis mysql

尻雨魔罗沙 10 years, 9 months ago

这样试试:


 <selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="id">  
          SELECT LAST_INSERT_ID() as ID    
    </selectKey>
     <![CDATA[
        insert into ...

    ]]>

Elvis、 answered 10 years, 9 months ago

Your Answer