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>
相关推荐
N维世界21 小时前
Mybatis-XML映射文件
xml·java·mybatis
慧一居士1 天前
MyBatis-Plus的完整使用示例,完整使用示例手册
mybatis
艺杯羹2 天前
MyBatis之核心对象与工作流程及SqlSession操作
java·mybatis
天天摸鱼的java工程师2 天前
MyBatis Plus 的实用技巧:从业务场景到代码实现
java·后端·mybatis
wuxuanok2 天前
Web后端开发-Mybatis
java·开发语言·笔记·学习·mybatis
netyeaxi2 天前
Java:使用spring-boot + mybatis如何打印SQL日志?
java·spring·mybatis
小七mod2 天前
【MyBatis】MyBatis与Spring和Spring Boot整合原理
spring boot·spring·mybatis
椰椰椰耶3 天前
【MyBatis】XML实现,配置方法和增、删、改、查
xml·oracle·mybatis
GJCTYU3 天前
spring中@Transactional注解和事务的实战理解附代码
数据库·spring boot·后端·spring·oracle·mybatis
DuelCode3 天前
Windows VMWare Centos Docker部署Springboot 应用实现文件上传返回文件http链接
java·spring boot·mysql·nginx·docker·centos·mybatis