MyBatis拼接批量SQL语句执行报错怎么解决
发表于:2025-11-07 作者:千家信息网编辑
千家信息网最后更新 2025年11月07日,这篇文章主要讲解了"MyBatis拼接批量SQL语句执行报错怎么解决",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"MyBatis拼接批量SQL语句执行
千家信息网最后更新 2025年11月07日MyBatis拼接批量SQL语句执行报错怎么解决
这篇文章主要讲解了"MyBatis拼接批量SQL语句执行报错怎么解决",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"MyBatis拼接批量SQL语句执行报错怎么解决"吧!
下载服务器基础业务数据进行本地批量插入操作,因项目中使用mybatis进行持久化操作,故直接考虑使用mybatis的批量插入功能。
1.以下是Mapper接口的部分代码
public interface PrintMapper{@InsertProvider(type = PrintMapperProvider.class,method = "insertAllLotWithVehicleCode4H2") void insertAllLotWithVehicleCode(List lotWithVehicleCodes);} 2.对应MapperProvider中函数片段
public String insertAllLotWithVehicleCode4H2(Map> map){List lotWithVehicleCodeBOs = map.get("list");StringBuilder sb = new StringBuilder("INSERT INTO MTC_LOT_WITH_VEHICLE_CODE (LOT_CODE,PRODUCT_VEHICLE_CODE) VALUES ");MessageFormat messageFormat = new MessageFormat("(" +"#'{'list[{0}].lotCode }," +"#'{'list[{0}].productVehicleCode }" +")"); int size = lotWithVehicleCodeBOs.size(); for (int i = 0; i < size; i++){sb.append(messageFormat.format(new Object[]{i})); if (i < size - 1) sb.append(",");} return sb.toString();}
3.service层
@Transactionalpublic void synchLotWithVehicleCodeToLocalDB(ListlotWithVehicleCodeBOs){ if(null != lotWithVehicleCodeBOs && lotWithVehicleCodeBOs.size()>0){printMapper.insertAllLotWithVehicleCode(lotWithVehicleCodeBOs);}}
程序上线的时候没有发生问题,在业务量猛增的时候,大约同时执行500条以上的时候程序就开始报错:
Caused by: org.apache.ibatis.builder.BuilderException: Improper inline parameter map format. Should be: #{propName,attr1=val1,attr2=val2}at org.apache.ibatis.builder.SqlSourceBuilder$ParameterMappingTokenHandler.buildParameterMapping(SqlSourceBuilder.java:89)at org.apache.ibatis.builder.SqlSourceBuilder$ParameterMappingTokenHandler.handleToken(SqlSourceBuilder.java:43)at org.apache.ibatis.parsing.GenericTokenParser.parse(GenericTokenParser.java:25)at org.apache.ibatis.builder.SqlSourceBuilder.parse(SqlSourceBuilder.java:24)at org.apache.ibatis.builder.annotation.ProviderSqlSource.createSqlSource(ProviderSqlSource.java:57)... 61 more异常已指明SQL语句构建问题,DEBUG进去:
问题根源:
MessageFormat messageFormat = new MessageFormat("(" +"#'{'list[{0}].lotCode }," +"#'{'list[{0}].productVehicleCode }," +")");int size = lotWithVehicleCodeBOs.size();for (int i = 0; i < size; i++){ sb.append(messageFormat.format(new Object[]{i})); if (i当size达到3位数以上时构建出的message为:
(#{list[1,000].lotCode },#{list[1,000].productVehicleCode })解决办法:messageFormat.format(new Object[]{i+""}
感谢各位的阅读,以上就是"MyBatis拼接批量SQL语句执行报错怎么解决"的内容了,经过本文的学习后,相信大家对MyBatis拼接批量SQL语句执行报错怎么解决这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是,小编将为大家推送更多相关知识点的文章,欢迎关注!
语句
问题
时候
学习
业务
内容
程序
业务量
代码
位数
函数
办法
功能
同时
基础
就是
思路
情况
接口
数据
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
河南做网络安全的公司
数据库中表示查询的关键字
金仓数据库创建数据库语句
炫舞的华南之约服务器
上位软件开发技术pdf
申论网络安全警情提示
服务器拓扑图
叨叨记账服务器无响应
松江区网络技术服务代理商
windows邮件服务器
飞升计划是哪国服务器
软件开发 小图片下载
软件开发兼职协议
过往相关学习经历计算机网络技术
如何进行服务器规划
政府单位网络安全管理方案
网络安全事件分为5类
安徽计算机软件开发费用是多少
监狱网络安全自查和整改报告
制作表格中的数据库在哪里
医学外文数据库有哪些
一台电脑怎么用两个数据库
excel找到某个数据库
如何查看服务器nginx已安装
学生网络安全教育宣传视频
后端项目部署到本地服务器
饥荒天亮与服务器断开连接
wepoker服务器在哪
阳泉天创软件开发有限公司
江苏工程软件开发定制价格