Map<String,Object> paymentMp = new HashMap<String,Object>(); paymentMp.put("amount", 12.0 ); paymentMp.put("pay", Attributes.Payment_Pay_No); paymentMp.put("status", Attributes.Payment_Status_NoStatus); paymentMp.put("payCode", Attributes.Payment_PayCode_ZhiFuBao ); dao.save("SearchCarMapper.paymentInsertWithNoPay", paymentMp); System.out.println("--id is:"+paymentMp.get("id"));
<insert id="paymentInsertWithNoPay" parameterType="java.util.HashMap" useGeneratedKeys="true" keyProperty="id" > <![CDATA[ insert into payment set amount=#{amount},body="",outTradeNO="",paidAmount=0.0,pay=#{pay},payCode=#{payCode},returnMoney=0.0,returnReason='', status=#{status},subject='',tradeNO='' ]]> </insert>
解释:
useGeneratedKeys:是否生成主键
keyProperty = "id" ,sql执行完毕后,传入参数HashMap 就会被自动附上id=新生成记录的id值