mybatis插入操作时获取主键

 /* 1.添加商品信息 */
        // 商品参数Map
        Map<String, Object> inGoodsMap = new HashMap<String, Object>();
        inGoodsMap.put("goodsId", 0);
        inGoodsMap.put("goodsBarCode", form.getBoxBar());
        inGoodsMap.put("goodsName", form.getGoodsName());
        inGoodsMap.put("goodsType", 1);
        inGoodsMap.put("goodsUnit", 1);
        inGoodsMap.put("price", tradeprice);
        inGoodsMap.put("tradePrice", retailprice);

        // 手动同步,添加商品信息
        dao.insert("GoodsService/handSyncInsertGoodsInfo", inGoodsMap);


<!-- 手动同步,添加商品信息 -->
	<insert id="GoodsService/handSyncInsertGoodsInfo" parameterType="java.util.HashMap" >
	
		<selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="goodsId">  
	        SELECT currval('goods_info_goodsid_seq') 
	    </selectKey>  
	
		INSERT INTO goods_info(
								goodsbarcode, 
								goodsname, 
								goodstype, 
								goodsunit, 
								price, 
            					tradeprice
            					)
  					VALUES 	( #{goodsBarCode},
   					 		  #{goodsName}, 
   					 		  #{goodsType},  
   					 		  #{goodsUnit}, 
   					 		  #{price}, 
             				  #{tradePrice})
	</insert>

你可能感兴趣的:(mybatis)