Mybatis查询in的字段过多不走索引

mybatis查询in的字段有索引,比如说是主键查询, 但是in的字段过多导致索引失效,

这个时候可以考虑将in的数量变少, 200以内都可以, 在数据库方面采用 foreach unionall 的方式将数据集合查询出来

c 复制代码
Service层:
List<List<String>> zffsDdbhList = Lists.partition(ddbhList, MagicNumber.INT200);

Dao层:
List<HotelKhSjzfxx> getListByDdbhArray(@Param("ywdh") List<List<String>> ywdh);

sql.xml:
<select id="getListByDdbhArray" resultType="cn.vetech.center.hotel.entity.HotelKhSjzfxx">
  SELECT * from (
        <foreach collection="ywdh" item="ddbhArray" index="index" separator="union all">
                SELECT *  FROM hotel_kh_sjzfxx
                WHERE ywdh in
                <foreach collection="ddbhArray" item="ddbh" open="(" separator="," close=")">
                        #{ddbh}
                </foreach>
        </foreach>
  ) t
 </select>
相关推荐
java1234_小锋3 小时前
讲讲Mybatis的一级、二级缓存?
java·开发语言·mybatis
情怀姑娘4 小时前
面试题---------------场景+算法
java·算法·mybatis
j***12156 小时前
Spring Boot与MyBatis
spring boot·后端·mybatis
java1234_小锋11 小时前
简述Mybatis的插件运行原理?
java·开发语言·mybatis
z***677720 小时前
SpringBoot(整合MyBatis + MyBatis-Plus + MyBatisX插件使用)
spring boot·tomcat·mybatis
b***67641 天前
Springboot3 Mybatis-plus 3.5.9
数据库·oracle·mybatis
k***1951 天前
Spring Boot中集成MyBatis操作数据库详细教程
数据库·spring boot·mybatis
e***74951 天前
SpringCloud 系列教程:微服务的未来(二)Mybatis-Plus的条件构造器、自定义SQL、Service接口基本用法
spring cloud·微服务·mybatis
chxii1 天前
在 Spring Boot 中,MyBatis 的“自动提交”行为解析
java·数据库·mybatis
有一个好名字2 天前
MyBatis-Plus 三种数据库操作方式详解 + 常用方法大全
数据库·mybatis