INSERT INTO `user` (userName) VALUES"/> INSERT INTO `user` (userName) VALUES">
search
HomeDatabaseMysql TutorialHow to operate mybaits batch insert
How to operate mybaits batch insertJun 21, 2017 pm 04:04 PM
Summarize

When we insert data in batches, we need to get the id of the inserted data.

This way:

 <insert>INSERT INTO `user`
        (userName)
        VALUES
        (#{userName})</insert>

This is no problem.

But sometimes it involves batch insertion, and to get the inserted id

write like this:

<insert>INSERT INTO `user`
        (userName)
        VALUES<foreach>(#{item.userName})</foreach></insert>

An exception will occur after running like this.

This is because the version of mybatis you are using is too low. For example, I am using version 3.2.2, which is a bug in mybatis.

If you switch to version 3.4.4, there will be no problem.

If the above sql statement is written differently, an exception will be reported again (enclose insert in foreach)

For example:

<insert> <foreach> INSERT INTO `user`
                (userName)
            VALUES
                (#{item.userName})         </foreach></insert>

Similarly, there is also update Batch update also has this problem

<update><foreach>update `user` set
                userName=#{item.userName}
            where
                userId=#{item.userId}</foreach></update>

This is because mybatis can only execute one sql statement by default.

You can add parameters when linking the path. Multiple sql statements were executed.allowMultiQueries=true

The above is the detailed content of How to operate mybaits batch insert. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
总结Linux系统中system()函数的用法总结Linux系统中system()函数的用法Feb 23, 2024 pm 06:45 PM

Linux下system()函数的总结在Linux系统中,system()函数是一个非常常用的函数,它可以用于执行命令行命令。本文将对system()函数进行详细的介绍,并提供一些具体的代码示例。一、system()函数的基本用法system()函数的声明如下:intsystem(constchar*command);其中,command参数是一个字符

Git工作流程管理经验总结Git工作流程管理经验总结Nov 03, 2023 pm 06:45 PM

Git工作流程管理经验总结引言:在软件开发中,版本管理是一个非常重要的环节。而Git作为目前最流行的版本管理工具之一,其强大的分支管理能力使得团队协作更加高效灵活。本文将就Git工作流程管理经验进行总结和分享。一、Git工作流程简介Git支持多种工作流程,可以根据团队的实际情况选择合适的工作流程。常见的Git工作流程有集中式工作流、功能分支工作流、GitF

探索自然本源!谷歌2022年终总结第七弹:「生化环材」如何吃上机器学习红利?探索自然本源!谷歌2022年终总结第七弹:「生化环材」如何吃上机器学习红利?Apr 11, 2023 pm 07:19 PM

随着机器学习和量子计算的巨大进步,我们现在有了更强大的新工具,能够以新的方式与各行业研究者合作,并从根本上加速突破性科学发现的进展。 本期谷歌年终总结的主题是「自然科学」,文章作者为谷歌研究院的杰出科学家John Platt,1989年博士毕业于加州理工大学。自从八年前加入 Google Research 以来,我有幸成为一个天才研究人员的社区的一员,致力于应用前沿计算技术来推动应用科学的可能性,目前团队正在探索物理和自然科学的课题,从帮助组织全世界的蛋白质和基因组信息以造福人们的生活,到利用量

ppt总结报告怎么写怎么才能写好ppt总结报告怎么写怎么才能写好Mar 19, 2024 pm 08:16 PM

总结报告是职场生存的必备技能,如果有一篇条理清晰的PPT总结报告,既可以节省领导的时间,又可以有重点的总结工作,一定可以让领导印象深刻。ppt总结报告怎么写呢?一起来看看吧!我们打开一个案例文件,根据这个案例进行讲解。这个案例看起来有点过时,具体可见下图。2、我们既然要修改刚刚的PPT,我们来针对性的讲解一下他存在的问题,具体如图示。3、这里为同学们介绍一个【配色】的网站,vanschneider.com网站,这里网站在配色方面还是非常的丰富,具体如图示。4、这里我们将PPT的文字素材准备好,然

ThinkPHP开发经验总结:提升开发效率的技巧ThinkPHP开发经验总结:提升开发效率的技巧Nov 22, 2023 pm 12:28 PM

ThinkPHP是一款流行的PHP开发框架,具有灵活、高效、易用等特点,被广泛应用于Web应用程序的开发中。在长期的开发实践中,我总结了一些提升开发效率的技巧,以下将分享给大家。一、充分利用ThinkPHP的核心功能ThinkPHP提供了众多强大的核心功能,如模型、视图、控制器等,我们需要充分利用这些功能来简化开发流程。首先,要正确使用MVC设计模式,将业务

百度AI接口在Java开发中的应用案例解析与总结百度AI接口在Java开发中的应用案例解析与总结Aug 13, 2023 pm 12:10 PM

百度AI接口在Java开发中的应用案例解析与总结随着人工智能技术的不断发展和应用,百度AI接口作为其中的一员,被广泛应用于各行各业。本文将对百度AI接口在Java开发中的应用案例进行解析与总结,通过代码示例来说明其具体的应用方式和效果。一、百度AI接口概述百度AI接口是基于百度的人工智能技术,通过API调用的方式提供给开发者使用的一套服务。它包含了丰富的功能

MySQL储存引擎的总结与对比:哪个适合你的业务需求?MySQL储存引擎的总结与对比:哪个适合你的业务需求?Jul 25, 2023 am 11:09 AM

MySQL储存引擎的总结与对比:哪个适合你的业务需求?引言:MySQL是一种广泛使用的关系型数据库管理系统,而储存引擎则是MySQL用于存储和管理数据的关键模块。MySQL提供了多种储存引擎,每种引擎都有其自己的特点和适用场景。本文将对MySQL常用的储存引擎进行总结和对比,并提供相应的业务需求建议。一、InnoDB引擎InnoDB是MySQL的默认储存引擎

总结CSS中的Margin属性总结CSS中的Margin属性Feb 18, 2024 pm 10:11 PM

CSS中margin属性总结CSS中的margin属性用来设置元素的外边距,它可以控制元素与周围元素之间的间距。本文将对margin属性进行总结,并提供一些具体的代码示例供参考。margin属性有四个值,分别表示元素上、右、下和左的外边距。可以使用以下几种方式来设置margin值:单个值:设置所有方向的外边距都相等。例如:.margin{margin:

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),