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. 【坑】tableView cell默认选中

    在tableView展示的过程时候,如果想一开始就有一些cell默认被选中,不能在cellForRowAtIndexPath中cell.selected=YES, 必须在willDisplayCell ...

  2. datasnap服务器支持的参数类型

    可作为参数的类型TDBXWideStringValueTDBXAnsiStringValueTDBXInt16ValueTDBXInt32ValueTDBXInt64ValueTDBXSingleVa ...

  3. c# GC 新典型

    public class testGC : MonoBehaviour { class XDict<K, V> { public void TryGetValue(K key, V val ...

  4. VMware Harbor学习

    同时安装Clair和Notary# ./install.sh --with-notary --with-clair 与notary或者Clair一起安装时管理Harbor的生命周期当Harbour与N ...

  5. Oracle VM VirtualBox各种显示模式切换 热键

    初用VirtualBox, 几个显示切换快捷键还是要记一下的: Right Ctrl + F        -- 切换到全屏模式 Right Ctrl + L        -- 切换到无缝模式 Ri ...

  6. idea将项目打成war包

    idea将项目打成war包(转载) 2018年02月28日 20:08:03 沈行的专栏 阅读数:13773更多 个人分类: Java   首先点击这里进入项目的配置页面 在Artifacts栏里点击 ...

  7. c 时间 学习

    linux #include <stdio.h> #include <time.h> int main(int argc,char **argv) { //两种时间的获取方法 ...

  8. 16.0 Auth0注册与设置

    首先呢?注册https://manage.auth0.com 填写回调网页,意思是当我们点sign in 那个按钮的时候 会访问这个官网 这个官网又回调下面的网页,不然会报错.这个网站因为我们是开发所 ...

  9. java-学习2

    第一节 Java语言介绍 1.Java的起源 Oak-->Java      交互式操作智能家居 2.Java的发展 Java1.0 Java1.2    JavaSE  :Java平台标准版  ...

  10. 转载一篇必须超级好的JVM配置实战

    不管是YGC还是Full GC,GC过程中都会对导致程序运行中中断,正确的选择不同的GC策略,调整JVM.GC的参数,可以极大的减少由于GC工作,而导致的程序运行中断方面的问题,进而适当的提高Java ...