码迷,mamicode.com
首页 > 移动开发 > 详细

mapper.xml中常用sql

时间:2020-05-14 10:27:30      阅读:80      评论:0      收藏:0      [点我收藏+]

标签:批量插入   pen   查找   模糊匹配   index   order by   nts   value   use   

1.模糊匹配,时间范围,集合用IN查找登的写法

SELECT * from tableName
<where> 1 = 1
<if test="vo.waybillPrintStatus != null and vo.waybillPrintStatus !=‘‘">
and waybillPrintStatus = #{vo.waybillPrintStatus}
</if>
<if test="vo.startTime != null and vo.startTime !=‘‘">
<![CDATA[ and time >= #{vo.startTime} ]]>
</if>
<if test="vo.endTime != null and vo.endTime !=‘‘">
<![CDATA[ and time <= #{vo.endTime} ]]>
</if>
<if test="postProvinceIds != null and postProvinceIds.size > 0">
and province IN
<foreach collection="postProvinceIds" open="(" close=")" separator="," item="item">
#{item}
</foreach>
</if>
</where>
order by time DESC

2.批量更新,如果为null的值给0,IFNULL函数

<update id="updatePrintStatus">
UPDATE t_custom_xiaohs_orders
SET
WaybillPrintStatus= #{waybillPrintStatus},
WaybillPrintCount = IFNULL(WaybillPrintCount, 0) + 1,
WaybillPrintTime = NOW()
WHERE Id in
<foreach collection="orderIds" index="index" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</update>

3.批量插入
<insert id="insertBatch" parameterType="java.util.List">
insert into t_cs_stock_goods_img
(good_code, good_img_id, good_address, good_sort, status, create_time, create_user, modify_time, modify_user)
values
<foreach collection="list" item="item" index="index" separator=",">
(
#{item.goodCode},#{item.goodImgId},#{item.goodAddress},#{item.goodSort},#{item.status},#{item.createTime},
#{item.createUser},#{item.modifyTime},#{item.modifyUser}
)
</foreach>
</insert>





mapper.xml中常用sql

标签:批量插入   pen   查找   模糊匹配   index   order by   nts   value   use   

原文地址:https://www.cnblogs.com/wan1992/p/12886743.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!