mybatis的一个比较先进的思想是把Sql语句写在了配置xml文件(也支持注解),通过配置文件的方式,免去了一般软件开发的硬编码,当业务需求改变的时候,只需要更改sql语句即可!

下面是个人在学习mybatis动态insert语句的笔记,留着参考!
在写insert子句的时候,由于不知道需要插入多少字段,mybatis通过prefix,suffix,suffixOverrides很好的解决了该问题,实现了动态insert语句。

<insert id="insertSelective" parameterType="com.bootdo.system.domain.LogDO">
insert into sys_log
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="userId != null">
user_id,
</if>
<if test="username != null">
username,
</if>
<if test="operation != null">
operation,
</if>
<if test="time != null">
time,
</if>
<if test="method != null">
method,
</if>
<if test="params != null">
params,
</if>
<if test="ip != null">
ip,
</if>
<if test="gmtCreate != null">
gmt_create,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=BIGINT},
</if>
<if test="userId != null">
#{userId,jdbcType=BIGINT},
</if>
<if test="username != null">
#{username,jdbcType=VARCHAR},
</if>
<if test="operation != null">
#{operation,jdbcType=VARCHAR},
</if>
<if test="time != null">
#{time,jdbcType=INTEGER},
</if>
<if test="method != null">
#{method,jdbcType=VARCHAR},
</if>
<if test="params != null">
#{params,jdbcType=VARCHAR},
</if>
<if test="ip != null">
#{ip,jdbcType=VARCHAR},
</if>
<if test="gmtCreate != null">
#{gmtCreate,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>

最新文章

  1. C#DataGridView合计处理
  2. [CareerCup] 1.8 String Rotation 字符串的旋转
  3. PC-1500与PC通讯
  4. linux常用命令--ps、netstat、find
  5. 内核同步机制 RCU
  6. 【Implement strStr() 】cpp
  7. hdu 1533 Going Home 最小费用最大流
  8. asp.net mvc 的几种分页Pager
  9. css 盒子模型理解
  10. 【HDOJ】1686 Oulipo
  11. js的兼容性问题
  12. Asp.net mvc4 + HighCharts + 曲线图
  13. UESTC_全都是秋实大哥 2015 UESTC Training for Search Algorithm &amp; String&lt;Problem J&gt;
  14. javascript日历插件
  15. Python新手需要掌握的知识点
  16. Mysql加锁过程详解(5)-innodb 多版本并发控制原理详解
  17. @ConfigurationProperties 配置详解
  18. Forth 输入流处理
  19. js计算base64文件流大小
  20. 自己写了一个解析json为table的工具类

热门文章

  1. Java实现 LeetCode 409 最长回文串
  2. linux下gdb调试方法与技巧整理
  3. UBoot配置编译及Makefile分析
  4. 小程序scroll-view实现回到顶部
  5. local 对象补充
  6. ArrayList、LinkedList、Vector、Array和HashMap、HashTable
  7. 多线程实现tcp聊天服务器
  8. 使用阿里云K8S 服务,丢失访问中原始IP 问题
  9. os:获取当前目录路径,上级目录路径,上上级目录路径
  10. 详说tcp粘包和半包