insertSelective---Java MyBatis 插入數據庫返回主鍵--insertSelective這樣就不用每次到數據庫裏面查詢了
https://www.cnblogs.com/xingyunblog/p/6243179.html
列子:
<!-- 插入一個商品 -->
<insert id="insertProduct" parameterType="domain.model.ProductBean" >
<selectKey resultType="java.lang.Long" order="AFTER" keyProperty="productId">
SELECT LAST_INSERT_ID()
</selectKey>
INSERT INTO t_product(productName,productDesrcible,merchantId)values(#{productName},#{productDesrcible},#{merchantId});
</insert>
我寫的:
<insert id="insertSelective" parameterType="com.runfast.waimai.dao.model.RunfastBusinessType"> <selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="id"> SELECT LAST_INSERT_ID() </selectKey> insert into newrunfast.runfast_business_type