批量插入
mybatis-plus默认的批量插入方法是假批量,所以需要我们自行做点扩展。
默认情况下,批量插入的sql会导致默认值无效。如金额字段,大多会在字段设计时,默认值为0,批量插入时会导致该字段设置为null.
代码实现
public interface BaseSqlMapper<T> extends BaseMapper<T> {
/**
* 默认批次提交数量
*/
int DEFAULT_BATCH_SIZE = 1000;
/**
* 以下定义的 4个 default method, copy from {@link com.baomidou.mybatisplus.extension.toolkit.ChainWrappers}
*/
default QueryChainWrapper<T> queryChain() {
return new QueryChainWrapper<>(this);
}
default LambdaQueryChainWrapper<T> lambdaQueryChain() {
return new LambdaQueryChainWrapper