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>
相关推荐
Yharim6 小时前
mybatis中一对一、多对多关联查询怎么实现
后端·mybatis
nangonghen1 天前
JAVA程序实现mysql读写分离并在kubernetes中演示
java·mysql·mybatis·读写分离
eternal__day1 天前
MyBatis-Plus 详解:快速上手到深入理解
java·spring boot·后端·spring·java-ee·maven·mybatis
愿你天黑有灯下雨有伞1 天前
MyBatis与MyBatis-Plus:字段自动填充的两种实现方式
java·mybatis
程序员黄老师1 天前
MyBatis 中 Mapper 传递参数的多种方法
java·tomcat·mybatis
wasteland~1 天前
MyBatis:SpringBoot结合MyBatis、MyBatis插件机制的原理分析与实战
spring boot·mybatis·插件机制·jdk代理
云之兕1 天前
MyBatis 如何使用
数据库·mybatis
bing_1581 天前
MyBatis-Plus 中BaseMapper接口是如何加速微服务内部开发的?
微服务·架构·mybatis
小杨4041 天前
springboot框架项目实践应用二十(扩展mybatis插件及原理解析)
spring boot·后端·mybatis
luoluoal2 天前
Java项目之基于ssm的QQ村旅游网站的设计(源码+文档)
java·mysql·mybatis·ssm·源码