在mybatis中构建带有sql in查询的mapper语法

在mapper中编写带有sql in语法的sql时,需要注意不能直接以字符串”in(…)”的形式将语句贴在sql中,需要以list集合的形式遍历出来,具体的表达方式如下:

1
2
3
4
5
6
7
8
9
10
<select id="selectAllServiceByServiceType" resultMap="BaseResultMap2" parameterType="java.util.List">
SELECT DISTINCT SERVICE_TYPE, IMAGE_TAG
FROM `SERVICE_CONFIG`
WHERE STATUS = 1
AND SERVICE_TYPE IN
<foreach collection="list" item="item" index="index" open="(" separator="," close=")">
#{item}
</foreach>
ORDER BY SERVICE_TYPE;
</select>
阅读更多
Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×