java
@Data
@Accessors(chain = true)
@TableName("mrp_flowmeter")
public class MrpFlowmeter implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(value = "water_meter_id", type = IdType.ID_WORKER_STR)
private String waterMeterId;
@TableField(value = "enterprise_Id",fill = FieldFill.INSERT)
private String enterpriseId;
@TableField(value = "create_uid",fill = FieldFill.INSERT)
private String createUid;
@TableField(value = "create_time",fill = FieldFill.INSERT)
private Date createTime;
@TableField(value = "modify_uid",fill = FieldFill.INSERT_UPDATE)
private String modifyUid;
@TableField(value = "modify_time",fill = FieldFill.INSERT_UPDATE)
private Date modifyTime;
}
sql
<insert id="insertBatchMrpFlowmeter">
INSERT INTO mrp_flowmeter (
water_meter_id,
bxwell_id,
group_id,
bxwell_remark,
flowmeter_num,
enterprise_Id,
dict_wms,
val,
caliber,
dict_ct,
meter_x,
meter_y,
longitude_and_latitude_gis,
meter_address,
cycle_val,
create_uid,
create_time,
modify_uid,
modify_time)VALUES
<foreach collection="list" item="item" separator=",">
(
#{item.waterMeterId},
#{item.bxwellId},
#{item.groupId},
#{item.bxwellRemark},
#{item.flowmeterNum},
#{item.enterpriseId},
#{item.dictWms},
#{item.val},
#{item.caliber},
#{item.dictCt},
#{item.meterX},
#{item.meterY},
ST_GeomFromText(#{item.longitudeAndLatitudeGis}),
#{item.meterAddress},
#{item.cycleVal},
#{item.createUid},
#{item.createTime},
#{item.modifyUid},
#{item.modifyTime}
)
</foreach>
</insert>
<update id="updateMrpFlowmeter">
UPDATE mrp_flowmeter
SET bxwell_id =#{bxwellId},
group_id =#{groupId},
bxwell_remark =#{bxwellRemark},
flowmeter_num =#{flowmeterNum},
dict_wms =#{dictWms},
val =#{val},
caliber =#{caliber},
dict_ct =#{dictCt},
meter_x =#{meterX},
meter_y =#{meterY},
longitude_and_latitude_gis =ST_GeomFromText(#{longitudeAndLatitudeGis}),
meter_address =#{meterAddress},
cycle_val =#{cycleVal},
modify_uid =#{modifyUid},
modify_time =#{modifyTime}
WHERE
water_meter_id = #{waterMeterId}
AND del_flag = '0'
</update>
我在service类里调用mapper类的insert跟update类操作数据之后,通用mybatis的自动生成值的方法,没有设置默认值。
原因在mapper层的方法参数里我加了@param(),我重写的mybatis的Handler类设置生成id,生成创建人修改人没有生成值。应该把@param()去掉。
sql
//正确
Integer insertBatchMrpFlowmeter(List<MrpFlowmeter> list);
sql
//错误
Integer insertBatchMrpFlowmeter(@param("list")List<MrpFlowmeter> list);
在这里有我重写的mybatis的自动生成创建人修改人的类 https://blog.csdn.net/hanjiaqian/article/details/109326009