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>
相关推荐
天若有情6733 小时前
SpringBoot4 + MyBatis 前后端分离实战|从零实现坏习惯管理系统,支持局域网手机访问CRUD
智能手机·mybatis
不能只会打代码4 小时前
Day 011 — Spring 全家桶深度拆解
spring boot·mybatis·spring aop·spring mvc·spring ioc
憧憬成为web高手18 小时前
皮卡丘靶场速通--sql 2
数据库·sql·mybatis
Java面试题总结2 天前
mybatis插件
java·tomcat·mybatis
Devin~Y3 天前
互联网大厂Java面试实战:Spring Boot、MyBatis、Redis、Kafka、JWT、Spring Cloud 与 AI 场景追问
java·spring boot·redis·spring cloud·kafka·mybatis·spring security
Ethan01073 天前
mybatis插件
mybatis
扎Zn了老Fe4 天前
MyBatis-Plus必知必会:告别低效CRUD,高效开发持久层
后端·mybatis
醉城夜风~4 天前
MyBatis 基础CRUD全套实战学习笔记
笔记·学习·mybatis
万亿少女的梦1684 天前
基于微信小程序、Spring Boot与Vue3的智慧养老管理系统设计与实现
spring boot·redis·微信小程序·mybatis·vue3
4154115 天前
MyBatis-Plus + PostGIS 实战(四):GeoJSON 序列化与前端地图对接,全局 WKT + 局部 GeoJSON,两种格式优雅共存
java·mybatis·postgis·geojson