mybatis使用foreach进行批量操作 The error may involve defaultParameterMap

落日映苍穹つ 2022-04-13 03:51 747阅读 0赞

触发现象

xml:

  1. <insert id="insertByList">
  2. <foreach collection="tagList" item="tag" separator=";">
  3. insert into table(name)
  4. select #{tag} from DUAL
  5. where not exists (select id from table where name = #{tag})
  6. </foreach>
  7. </insert>

异常信息:

  1. ### The error may involve defaultParameterMap
  2. ### The error occurred while setting parameters

报错原因

mybatis不支持一次性插入多条的语法

解决办法

修改mybatis的连接参数,同意插入多条语法。添加allowMultiQueries=true

  1. #不支持插入多条的语法示例
  2. spring.datasource.url=jdbc:mysql://xxx:3306/xxx
  3. #支持插入多条的连接参数示例
  4. spring.datasource.url=jdbc:mysql://xxx:3306/xxx?allowMultiQueries=true

对你有帮助的话,右上角给个赞呗~

发表评论

表情:
评论列表 (有 0 条评论,747人围观)

还没有评论,来说两句吧...

相关阅读