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() ">
    原创打造,多多指教
  • 相关阅读:
    C#的ugui与XLua整合的案例
    关于C#调用XLua的函数抛出attempt to call a nil value (global 'print')
    关于文件上传的坑,tomcat一重启图片就消失
    linux服务器安装zookeeper本地项目远程连接
    使用eazyExcel读取数据结合mybatis批量保存到数据库(优化批量保存)
    jpa set值持久化解决办法
    cascade级联关系
    @JoinTable和@JoinColumn
    json操作容易出现的细微问题
    attr和prop的区别
  • 原文地址:https://www.cnblogs.com/iscys/p/9550222.html
Copyright © 2011-2022 走看看