总结下常用mybatis xml的写法
1、in语法
批量更新
<update id="batchUpdatePutwayStatus">
update talent_course set putaway_status = #{putwayStatus} where id in
<foreach collection="courseIds" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</update>
批量查询
<select id="selectNoPeriodCourses" resultType="xxx">
SELECT
`talent_course`.*
FROM `talent_course`
LEFT JOIN `talent_course_chapter_period` ON `talent_course`.`id` = `talent_course_chapter_period`.`course_id`
WHERE `talent_course`.`id` IN
<foreach collection="courseIds" item="value" separator="," open="(" close=")">
#{value}
</foreach>
GROUP BY `talent_course`.`id`
HAVING COUNT(talent_course_chapter_period.`id`) = 0
</select>
2、sql引用
首先在xml文件中写一段如下复杂的xml
<sql id="commonQueryPageCourseUser">
select * from demo
</sql>
在引用的地方这么写
<select id="queryPageCourseUser" resultType="xxx"
parameterType="xxx">
<include refid="commonQueryPageCourseUser"/>
GROUP BY
uc.user_id,
uc.course_id
</select>
注意:本文归作者所有,未经作者允许,不得转载