trim元素的主要功能是可以在自己包含的内容前加上某些前缀,也可以在其后加上某些后缀,与之对应的属性是prefix和suffix;可以把包含内容的首部某些内容覆盖,即忽略,也可以把尾部的某些内容覆盖,对应的属性是prefixOverrides和suffixOverrides;

<insert id="operatorLog" parameterType="com.oa.model.wxlog.WxLog">
INSERT INTO sdb_oa_operator_log
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="open_id!='' and open_id != null">
open_id,
</if>
<if test="operatortime!='' and operatortime != null">
operatortime,
</if>
<if test="operatortype!='' and operatortype != null">
operatortype,
</if>
<if test="operatorcont!='' and operatorcont != null">
operatorcont,
</if>
<if test="ip!='' and ip != null">
ip,
</if>
</trim>
<trim prefix="values(" suffix=")" suffixOverrides="," >
<if test="open_id!='' and open_id != null">
#{open_id},
</if>
<if test="operatortime!='' and operatortime != null">
#{operatortime},
</if>
<if test="operatortype!='' and operatortype != null">
#{operatortype},
</if>
<if test="operatorcont!='' and operatorcont != null">
#{operatorcont},
</if>
<if test="ip!='' and ip != null">
#{ip},
</if>
</trim>
</insert>
Mybatis 配置文件 useGeneratedKeys 参数只针对 insert 语句生效,默认为 false。
当设置为 true 时,表示如果插入的表以自增列为主键,则允许 JDBC 支持自动生成主键,并可将自动生成的主键返回。
<insert id="saveMain" parameterType="java.util.HashMap" keyProperty="id" useGeneratedKeys="true">
insert into <include refid="tableName"></include>(
<include refid="Field"></include>
) values (
<include refid="FieldValue"></include>
)
</insert>

--------------Mybatis 拼接like ---

 and date_format(company.create_time,'%Y-%m-%d %H:%i:%s') LIKE CONCAT('%', '${params.create_time}', '%')

----------------mybatis 判断参数要加.toString()---

<if test="params.selectTime =='2'.toString() ">

Mybatis常用标签使用的更多相关文章

  1. MyBatis - 常用标签与动态Sql

    MyBatis常用标签 ● 定义sql语句:select.insert.delete.update ● 配置JAVA对象属性与查询结构及中列明对应的关系:resultMap ● 控制动态sql拼接:i ...

  2. Mybatis 常用标签

    MyBatis 的强大特性之一便是它的动态 SQL.如果你有使用 JDBC 或其他类似框架的经验,你就能体会到根据不同条件拼接 SQL 语句有多么痛苦.拼接的时候要确保不能忘了必要的空格,还要注意省掉 ...

  3. [Mybatis]Mybatis 常用标签及功能整理

    Mybatis中生成动态SQL的标签有四类,分别是: if choose (when, otherwise) trim (where, set) foreach 1.if 当需要动态生成where条件 ...

  4. mybatis常用标签

    1. 定义sql语句 1.1 select 标签 属性介绍: id :唯一的标识符. parameterType:传给此语句的参数的全路径名或别名 例:com.test.poso.User或user ...

  5. mybatis常用标签(转)

    1. 定义sql语句 select 标签 属性介绍: id :唯一的标识符. parameterType:传给此语句的参数的全路径名或别名 例:com.test.poso.User或user resu ...

  6. [刘阳Java]_MyBatis_映射文件的常用标签总结_第5讲

    MyBatis中常用标签的总结,简单给出自己的总结 MyBatis映射文件中的标签使用介绍1.<select>:用于编写查询语句用的标签 id:表示当前<select>标签的唯 ...

  7. Mybatis 常用注解

    Mybatis常用注解对应的目标和标签如表所示: 注解 目标 对应的XML标签 @CacheNamespace 类 <cache> @CacheNamespaceRef 类 <cac ...

  8. Mybatis foreach标签含义

    背景 考虑以下场景: InfoTable(信息表): Name Gender Age Score 张三 男 21 90 李四 女 20 87 王五 男 22 92 赵六 女 19 94 孙七 女 23 ...

  9. MyBatis 常用写法

    MyBatis 常用写法 1.forEach 循环   forEach 元素的属性主要有 item, idnex, collection, open, separator, close. collec ...

随机推荐

  1. linux 不同服务器之间复制文件

    ----------------------拷贝文件夹---------------------------------------------- 把当前文件夹tempA拷贝到 目标服务器10.127 ...

  2. css:margin和padding的百分之使用

    #app { position: fixed; width: 94%; height: 100%; background: pink; padding: 0px 3% 0px 3%;} 如上代码,最终 ...

  3. 【转】【java】论integer是地址传递还是值传递

    转自:http://www.tuicool.com/articles/AraaQbZ 论integer是地址传递还是值传递 Integer 作为传参的时候是地址传递 , 可以参考如下例子,在程序刚启动 ...

  4. 【359】scikit learn 官方帮助文档

    官方网站链接 sklearn.neighbors.KNeighborsClassifier sklearn.tree.DecisionTreeClassifier sklearn.naive_baye ...

  5. php 查看当前页中的post及get数据

    file_put_contents("log1209.html",date('Y-m-d H:i:s ')."-----<br>",FILE_APP ...

  6. [PHP]PHPOffice/PHPExcel数据导入方法

    ------------------------------------------------------------------------------------ /** * PHPExcel数 ...

  7. shell定时任务crontab

    cat /etc/crontab SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root HOME=/ # For details ...

  8. 24.类的加载机制和反射.md

    目录 1类的加载连接和初始化 1.1类的加载过程 1.2类的加载器 1.2.1类的加载机制 1类的加载连接和初始化 1.1类的加载过程 类的加载过程简单为分为三步:加载->连接->初始化 ...

  9. Working with the Dynamic Type in C#

    Working with the Dynamic Type in C# https://www.red-gate.com/simple-talk/dotnet/c-programming/workin ...

  10. Java happen-before

    下面是happens-before原则规则: 程序次序规则:一个线程内,按照代码顺序,书写在前面的操作先行发生于书写在后面的操作: 锁定规则:一个unLock操作先行发生于后面对同一个锁额lock操作 ...