最近在项目中有这么一段代码:下载服务器基础业务数据进行本地批量插入操作,因项目中使用mybatis进行持久化操作,故直接考虑使用mybatis的批量插入功能。

1.以下是Mapper接口的部分代码

public interface PrintMapper{@InsertProvider(type = PrintMapperProvider.class,method = "insertAllLotWithVehicleCode4H2") void insertAllLotWithVehicleCode(List<LotWithVehicleCodeBO> lotWithVehicleCodes);}
public String insertAllLotWithVehicleCode4H2(Map<String,List<LotWithVehicleCodeBO>> map){List<LotWithVehicleCodeBO> 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();}
@Transactionalpublic void synchLotWithVehicleCodeToLocalDB(List<LotWithVehicleCodeBO> lotWithVehicleCodeBOs){ if(null != lotWithVehicleCodeBOs && lotWithVehicleCodeBOs.size()>0){printMapper.insertAllLotWithVehicleCode(lotWithVehicleCodeBOs);}}
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

问题根源:

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(",");}
(#{list[1,000].lotCode },#{list[1,000].productVehicleCode })

更多相关文章

  1. Android(安卓)报错:Caused by: android.os.FileUriExposedExcepti
  2. Ionic 运行报错No resource identifier found for attribute 'ap
  3. Android,LIstView中的OnItemClick点击无效的解决办法
  4. 华为手机Android(安卓)Studio开发不显示Logcat解决办法
  5. 安卓9.0 http请求数据失败解决办法
  6. Android(安卓)Studio 导入包时报 Duplicate files copied in APK
  7. Android(安卓)启动Tomcat服务报错,端口占用解决方案
  8. Android(安卓)启动时闪一下黑屏问题的解决办法
  9. Android(安卓)项目混编flutter报错

随机推荐

  1. android多媒体框架之流媒体----base on j
  2. 阅读《Android(安卓)从入门到精通》(17)—
  3. (转载)再谈Android AsyncTask
  4. Android Studio在Gradle中隐藏Keystore密
  5. Ubuntu10.04 32位编译Android 4.0源码
  6. Android定时器的使用,
  7. Android手势滑动(左滑和右滑)
  8. 用网络adb连接调试Android
  9. Android常见问题总结(七)
  10. Android BitmapShader 实战 实现圆形、圆