zoukankan      html  css  js  c++  java
  • Mybatis常用标签使用

    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() ">
    原创打造,多多指教
  • 相关阅读:
    报表开发之扩展GROUP BY
    Leetcode--easy系列9
    datatable 前台和后台数据格式
    C实现头插法和尾插法来构建单链表(带头结点)
    HDOJ 题目1520 Anniversary party(树形dp)
    windows环境利用apache 配置虚拟主机
    POJ--1966--Cable TV Network【无向图顶点连通度】
    Linux Shell脚本编程学习笔记和实战
    win10 bcdedit加入vhdx启动
    设计模式之Mediator模式(笔记)
  • 原文地址:https://www.cnblogs.com/iscys/p/9550222.html
Copyright © 2011-2022 走看看