误使用arrays.aslist方法带来的惨痛

本文介绍在MyBatis中使用IN关键字进行查询时,如何通过List、数组及Map三种方式进行参数传递,并提供具体的XML配置示例。此外,还分享了在实际应用过程中遇到的问题及其解决方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在mybaties中,要使用in进行查询,有三种传参方式:list,数组,map

      1、list

       select * from pub_user_role
            <where>
                area_code in
                <foreach collection="list" index="index" item="item" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </where>   

       2、list

        select * from pub_user_role
            <where>
                area_code in
                <foreach collection="array" index="index" item="item" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </where>

       3、map

      select * from pub_user_role
            <where>
                area_code in
                <foreach collection="ids" index="index" item="item" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </where>

    此处的ids为封装在map里面的key值

前端传过来的参数为逗号分开的值,如:a,b,c,d等等。

再将次字符串转为list时,误使用arrays.aslist方法将其转为list,在使用pagehelp分页插件时,始终不显示第二页以后的数据,找了好久之后才发现是将参数转为list时出现了问题。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值