Mapper的内容如下:
package com.xxx.user.mapper;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.xxx.user.entity.TbSysUserPhoneBelong;
import java.util.List;
/**
*
* 功能:
*
*
* @author tuzq
* Copyright 2018 xxx.com, Inc. All rights reserved
* @version v1.0
* @ClassName: xxxx
* @date 2018/3/22
*/
public interface TbSysUserPhoneBelongMapper extends BaseMapper {
/**
* 归属地相关的批处理
* @param phoneBelongs :归属地list
*/
public void insertBatch(@Param("phoneBelongs")List phoneBelongs);
}
xml的内容如下:
要注意的是,不要INSERT INTO里面不要加id
SELECT LAST_INSERT_ID()
INSERT INTO
xxxxx
(
xxx,
xxx,
xxx,
xxx,
xxx,
xxx,
xxx,
xxx,
xxx,
xxx,
xxx,
xxx,
xxx,
xxx,
xxx
)
VALUES
(
#{item.id},
#{item.xxx},
#{item.xxx},
#{item.types},
#{item.xxx},
#{item.xxx},
#{item.xx},
#{item.xxx},
#{item.xxx},
#{item.xxx},
#{item.xxx},
#{item.xxx},
#{item.xxx},
#{item.xxx},
#{item.xxx}
)
批量更新
具体参考:https://blog.csdn.net/xyjawq1/article/details/74129316
Mapper.java文件中的定义如下:
public void updateBatchById(@Param("keywordsList")List keywordsList);
mapper.xml中的内容如下
update mydata_table
when id=#{item.id} then #{item.status}
where id in
#{item.id,jdbcType=BIGINT}
方法二:
UPDATE
XXX
article_id = #{item.articleId},
keywords = #{item.keywords},
xxxxxx
WHERE
id = #{item.id}
这种方法可能会报:
Caused by: java.sql.SQLException: sql injection violation, multi-statement not allow : update device_bd_token
SET access_token=?
where device_id = ?
;
update device_bd_token
SET access_token=?
where device_id = ?
at com.alibaba.druid.wall.WallFilter.check(WallFilter.java:714)
at com.alibaba.druid.wall.WallFilter.connection_prepareStatement(WallFilter.java:240)
at com.alibaba.druid.filter.FilterChainImpl.connection_prepareStatement(FilterChainImpl.java:448)
at com.alibaba.druid.filter.FilterAdapter.connection_prepareStatement(FilterAdapter.java:928)
at com.alibaba.druid.filter.FilterEventAdapter.connection_prepareStatement(FilterEventAdapter.java:122)
at com.alibaba.druid.filter.FilterChainImpl.connection_prepareStatement(FilterChainImpl.java:448)
at com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl.prepareStatement(ConnectionProxyImpl.java:342)
at com.alibaba.druid.pool.DruidPooledConnection.prepareStatement(DruidPooledConnection.java:318)
原因是druid给控制住了,解决办法是: