在写insert子句的时候,由于不知道需要插入多少字段,mybatis通过prefix,suffix,suffixOverrides很好的解决了该问题,实现了动态insert语句。

用这种动态插入时<if test=""></test>这里test的字段一定不要写错,本来直接写字段名就可以了,写错为#字段名 就不起作用了

<insert >
#{gmtCreate,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>

顺便记一下批量插入

Mapper接口中提供
public void batchSave(List<Emp> empList);

Mapper.xml提供

<insert >
(#{emp.empName}, #{emp.empEmail}, #{emp.deptId})
</foreach>
</insert>

相关文章:

  • 2022-12-23
  • 2021-10-04
  • 2022-12-23
  • 2021-12-05
  • 2021-11-16
  • 2021-08-21
  • 2022-02-02
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-22
  • 2022-02-13
  • 2022-12-23
  • 2022-01-11
  • 2022-12-23
相关资源
相似解决方案