在mybatis中构建带有sql in查询的mapper语法
在mapper中编写带有sql in语法的sql时,需要注意不能直接以字符串"in(…)"的形式将语句贴在sql中,需要以list集合的形式遍历出来,具体的表达方式如下:
1 | <select id="selectAllServiceByServiceType" resultMap="BaseResultMap2" parameterType="java.util.List"> |
上面得到的sql也就是:
1 | SELECT DISTINCT SERVICE_TYPE, IMAGE_TAG |
这里需要注意的是,foreach中的collection字段的list值是固定表达方式,在对应的mapper方法中,传入参数名也应为list,具体表示如下:
1 | List<ServiceConfig> selectAllServiceByServiceType(List<Integer> list); |