zoukankan      html  css  js  c++  java
  • MyBatis 特殊标签使用例子

    foreach、if 、where

      <insert id="batchInsert" parameterType="list">
        insert into mmall_order_item (id, order_no,user_id, product_id,
        product_name, product_image, current_unit_price,
        quantity, total_price, create_time,
        update_time)
        values
        <foreach collection="orderItemList" index="index" item="item" separator=",">
          (
          #{item.id},#{item.orderNo},#{item.userId},#{item.productId},#{item.productName},
        #{item.productImage},#{item.currentUnitPrice},#{item.quantity},#{item.totalPrice},now(),now() )
    </foreach> </insert>
     <update id="updateByPrimaryKeySelective" parameterType="com.pojo.OrderItem" >
        update order_item
        <set >
          <if test="userId != null" >
            user_id = #{userId,jdbcType=INTEGER},
          </if>
          <if test="orderNo != null" >
            order_no = #{orderNo,jdbcType=BIGINT},
          </if>
          <if test="updateTime != null" >
            now(),
          </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
      </update>
     <insert id="insertSelective" parameterType="com.mmall.pojo.PayInfo" >
        insert into mmall_pay_info
        <trim prefix="(" suffix=")" suffixOverrides="," >
          <if test="id != null" >
            id,
          </if>
          <if test="userId != null" >
            user_id,
          </if>
          <if test="updateTime != null" >
            update_time,
          </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides="," >
          <if test="id != null" >
            #{id,jdbcType=INTEGER},
          </if>
          <if test="userId != null" >
            #{userId,jdbcType=INTEGER},
          </if>
          <if test="updateTime != null" >
            now(),
          </if>
        </trim>
      </insert>
    <select id="selectByNameAndProductId" resultMap="BaseResultMap" parameterType="map">
      select
        <include refid="Base_Column_List"/>
        FROM
        mmall_product
        <where>
          <if test="productName != null">
            and name like #{productName}
          </if>
          <if test="productId != null">
            and id = #{productId}
          </if>
        </where>
      </select>
  • 相关阅读:
    nodejs中处理回调函数的异常
    Web前端开发十日谈
    Android 高仿微信6.0主界面 带你玩转切换图标变色
    Android EventBus源码解析 带你深入理解EventBus
    Android EventBus实战 没听过你就out了
    究竟谁在绑架中国的4G政策?
    Android 实战美女拼图游戏 你能坚持到第几关
    oracle学习
    his使用-重置密码
    oracle中的DDL、DML、DCL
  • 原文地址:https://www.cnblogs.com/SacredOdysseyHD/p/9095269.html
Copyright © 2011-2022 走看看