
insert into questionBank 
 <if test="list != null and list.size > 0"&g;
 <foreach collection="list" item="myList" separator=",">
 <if test="myList != null">
 (
 <if test="myList.pdId !=null">pdid</if>
 <if test="myList.answer != null"> ,answer</if>
 <if test="myList.testType != null"> ,testType</if>
 <if test="myList.questionTitle != null">,questionTitle</if> 
 ) values( 
 <if test="myList.pdId !=null"> #{myList.pdId}</if>
 <if test="myList.answer != null"> , #{myList.answer}</if>
 <if test="myList.testType != null"> , #{myList.testType}</if>
 <if test="myList.questionTitle != null"> , #{myList.questionTitle}</if>
 ) </if></foreach></if>
 这样写不行吗,因为我要判断参数中的 key 是否为空,才好插入数据,所以对 key 进行判断 |      1luman      2017-04-24 09:36:51 +08:00 | 
|      2jwh199588 OP @sunjiayao 很感谢你,大但是你看到我的 sql 语句了吗,我的 key 和 values 全部都是需要判断的,不然 key 存在,但是没有值的话 sql 语句也是不成立的啊 | 
|      3luman      2017-04-24 09:48:56 +08:00 https://dev.mysql.com/doc/refman/5.7/en/insert.html  sorry ,确实没仔细看。你应该看这个文档 | 
|  |      4jason19659      2017-04-24 10:19:47 +08:00 @sunjiayao #3 6666666 | 
|      5freelee      2017-04-24 10:36:11 +08:00 多行插入应该是 insert into(字段 1) values(值 1),(值 2)吧,你这字段也有两遍,当然有问题 |