Mybatis 动态insert语句
来源:互联网 发布:淘宝类目在哪里设置 编辑:程序博客网 时间:2024/06/08 11:52
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>
阅读全文
0 0
- Mybatis 动态insert语句
- mybatis insert新增语句
- mybatis的insert语句
- MyBatis 动态插入 数据 insert
- mybatis动态SQL语句
- mybatis动态SQL语句
- mybatis动态SQL语句
- MyBatis 动态SQL语句
- mybatis 动态SQL语句
- mybatis 动态sql语句
- mybatis动态SQL语句
- Mybatis 动态SQL语句
- mybatis动态sql语句
- MyBatis动态SQL语句
- Mybatis动态sql语句
- mybatis动态SQL语句
- mybatis 动态SQL语句
- mybatis动态SQL语句
- bootstrap中获取当前的图片索引值
- Linux 学习笔记--不熟悉的命令 (一)
- Python日志输出——logging模块
- git的工作用到的命令
- 制作自己的物体检测数据集----MS COCO: Common Object in Context笔记
- Mybatis 动态insert语句
- Web Service学习笔记(webservice、soap、wsdl、jws详细分析)
- 文件上传fileupload实现
- shiro:realm域实例
- java三目运算符
- 第四周 项目1 建立单链表
- IntelliJ Idea各种技巧设置笔记和错误解决
- SpringMVC 框架个人总结
- linux命令行日志输出 在android studio gradlew 中的应用