创建表,多列唯一索引
CREATE TABLE ${tableName} (
`GRID_ID` bigint(20) NOT NULL AUTO_INCREMENT,
`GRID_SN` varchar(64) CHARACTER SET utf8 DEFAULT NULL,
......
PRIMARY KEY (`GRID_ID`)
UNIQUE INDEX `MultipleColumnsKey` (`GRID_ROAD_WAY`,`GRID_NUMBER`,`GRID_ROW`,`GRID_COLUMN`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
mybatis批量插入,数据表里有数据就更新为原有数据+当前value,没有数据就插入新的记录
<insert id="insertIntoGrid" parameterType="java.util.List">
INSERT INTO ${tableName}
(GRID_SN, GRID_NUMBER,
.......)
VALUES
<foreach collection="list" item="item" index="index" separator=",">
(#{item.gridSn,jdbcType=VARCHAR}, #{item.gridNumber,jdbcType=REAL},
.......
</foreach>
ON DUPLICATE KEY UPDATE GRID_PAVER_NUMBER= `GRID_PAVER_NUMBER` + values( GRID_PAVER_NUMBER),
GRID_COMPACTOR_R_NUMBER= `GRID_COMPACTOR_R_NUMBER`+ values(GRID_COMPACTOR_R_NUMBER),
......
网友评论