mapper:
<update id="updateSurplusAmountByPrimaryKeyAndMaterialTypeId"
parameterType="java.util.List">
update db_logistics.table_inventory_material
set surplusAmount=
<foreach collection="list" item="item" index="index"
separator=" " open="case" close="end">
when inventoryId=#{item.inventoryId} and materialTypeId=#
{item.materialTypeId} then #{item.surplusAmount,jdbcType=INTEGER}
</foreach>
where inventoryId in
<foreach collection="list" index="index" item="item"
separator="," open="(" close=")">
#{item.inventoryId,jdbcType=BIGINT}
</foreach>
</update>
fun updateSurplusAmountByPrimaryKeyAndMaterialTypeId(records:
List<InventoryMaterial>): Int
data class InventoryMaterial(
var inventoryId: Int = 0,
var materialTypeId: Int = 0,
var surplusAmount: Int = 0,
var consumeSpeed: Float = 0f,
var consumeAlarmDayCount: Int = 0,
var updateDataTime: LocalDateTime = LocalDateTime.now())
错误
“原因:com.mysql.jdbc.exceptions.jdbc4.mysqlintegrityconstraintviolationexception:列‘盈余金额’不能为空”
当我修改 when inventoryId=#{item.inventoryId} and materialTypeId=#{item.materialTypeId}
至 when inventoryId=#{item.inventoryId}
,则错误消失。但是我需要两个参数inventoryid和materialtypeid来决定inventoryid。有人能给我一些答案吗?
1条答案
按热度按时间bd1hkmkf1#
执行的查询从中选择记录
table_inventory_material
由inventoryId
并使用每个materialTypeId
.问题的出现是因为
inventoryId
你在数据库中传递的列表materialTypeId
在作为参数传递的列表中提供的。所以生成的case语句
NULL
为了失踪的人materialTypeId
以及试图surplusAmount
至NULL
导致错误。