美文网首页
mybatis常用

mybatis常用

作者: 缘木与鱼 | 来源:发表于2019-11-29 17:53 被阅读0次

动态 update

<update id="updateTable" parameterType="com.asiainfo.pojo.Table">
    update Table
    <trim prefix="set" suffixOverrides=",">
        <if test="OLDPOLICY != null">OLDPOLICY = #{OLDPOLICY},</if>
        <if test="QOS != null">QOS = #{QOS},</if>
        <if test="START_TIME != null">START_TIME = #{START_TIME},</if>
        <if test="END_TIME != null">END_TIME = #{END_TIME},</if>
    </trim>
    where MSISDN = #{MSISDN} and ID =#{ID}
</update>

动态查询 (包含时间的比较, 取某个时间段之间的数据)

// service层, 时间为字符串格式
HashMap<String, String> orderMap = new HashMap<>();
orderMap.put("status", status);
orderMap.put("order_id", order_id);
orderMap.put("create_time_start", create_time_start);
orderMap.put("create_time_end", create_time_end);
List<Order> orders = adminSearchMapper.getOrders(orderMap);

// mapper接口层
List<Order> getOrders(HashMap<String, String> map);

// mapper.xml 层
<select id="getOrders" parameterType="HashMap" resultType="Order">
     select * from `order` where 1=1
     <if test="create_time_start != null and create_time_start != ''"> and create_time >= #{create_time_start}</if>
     <if test="create_time_end != null and create_time_end != ''"> and #{create_time_end} >= create_time</if>
     <if test="cust_id != null and cust_id != ''"> and cust_id like #{cust_id}</if>
     <if test="status != null and status != ''"> and status = #{status}</if>
     <if test="id != null and id != ''"> and id = #{id}</if>
     order by create_time desc
</select>

相关文章

网友评论

      本文标题:mybatis常用

      本文链接:https://www.haomeiwen.com/subject/pdbgwctx.html