mybatis中insert into ...select ...from dual union all select ... from dual 提示sql命令未結束的問題

suyunlong發表於2017-05-06

需要在插入時加上useGeneratedKeys="false"

原Mapper:

<insert id="insertProductRoleUser" parameterType="list">	 
	 	INSERT INTO AMC_PRODUCT_ROLE_USER
	   		(user_id, role_id)
		<foreach collection="list" item="productRole" index="index" separator="union all">
			SELECT 
				#{productRole.user_id,jdbcType=VARCHAR},
				#{productRole.role_id,jdbcType=VARCHAR} 
			FROM DUAL
		</foreach> 
    </insert>

新Mapper:

<insert id="insertProductRoleUser" parameterType="list" useGeneratedKeys="false">	 
	 	INSERT INTO AMC_PRODUCT_ROLE_USER
	   		(user_id, role_id)
		<foreach collection="list" item="productRole" index="index" separator="union all">
			SELECT 
				#{productRole.user_id,jdbcType=VARCHAR},
				#{productRole.role_id,jdbcType=VARCHAR} 
			FROM DUAL
		</foreach> 
    </insert>


相關文章