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>
相关推荐
misL NITL1 天前
idea、mybatis报错Property ‘sqlSessionFactory‘ or ‘sqlSessionTemplate‘ are required
tomcat·intellij-idea·mybatis
是宇写的啊1 天前
MyBatis-Plus
java·开发语言·mybatis
工作log2 天前
Spring Boot 3.5 + MyBatis Plus + RabbitMQ:打造 AI 驱动的慢 SQL 监控与优化系统
spring boot·mybatis·java-rabbitmq
河阿里3 天前
MyBatis-Plus:MyBatis的进阶开发
数据库·mybatis
橙子圆1233 天前
Mybatis之动态sql
sql·tomcat·mybatis
冷小鱼3 天前
MyBatis 与 MyBatis-Plus:从入门到精通的完整指南
java·tomcat·mybatis
香香甜甜的辣椒炒肉4 天前
SpringMVC高级应用和MyBatis-Plus的概念和使用
mybatis
鸡蛋灌Bean4 天前
mybatis分页深入了解
java·数据库·mybatis
看腻了那片水4 天前
开源一个对业务代码零侵入的透明数据治理框架 —— 【sangsang】
java·mybatis
ffqws_4 天前
MyBatis 动态 SQL 详解:从原理到实战
java·sql·mybatis