场景一:数据表之间不存在外键联系
步骤一:在数据库连接文件中打开批量操作,否则报错 BadSqlGrammarException
allowMultiQueries = true
步骤二:编写数据库插入语句
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/db.nuc?useSSL=true&useUnicode=true&characterEncoding=utf8&allowMultiQueries=true
jdbc.username=root
jdbc.password=root
INSERT INTO student(studentid,studentname,studentpassword) VALUES(#{studentid},#{studentname},#{studentpassword});
INSERT INTO studentquery(studentid,studentclass) VALUES(#{studentid},#{studentquery.studentclass});
场景二:数据表之间存在外键联系
步骤一:在数据库连接文件中打开批量操作,否则报错 BadSqlGrammarException
allowMultiQueries = true
步骤二:编写批量插入语句【先插入主表数据,再插入和主表存在外键约束的表数据】
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/db.nuc?useSSL=true&useUnicode=true&characterEncoding=utf8&allowMultiQueries=true
jdbc.username=root
jdbc.password=root
INSERT INTO student(studentid,studentname,studentpassword) VALUES(#{studentid},#{studentname},#{studentpassword});
INSERT INTO studentquery(studentid,studentclass) VALUES(#{studentid},#{studentquery.studentclass});