MybatisPlus中使用in查询结果0,通过mybatis-plus生成的sql在数据库中查询有数据,这种问题如何解决

java代码这个是mybatis-plus的执行结果是0,但是用mysql跑出来是有数据的。如下SQL语句

11:56:32.666 [http-nio-8103-exec-10] DEBUG c.n.a.m.I.selectItDeviceList - [debug,137] - ==>  Preparing: SELECT td.device_id, td.device_name, td.device_code, td.device_type, ( SELECT dict_label FROM sys_dict_data AS dd WHERE dd.dict_type = 'am_device_type' and dd.dict_value = td.device_type ) AS device_type_name, td.site_id, s.site_name, td.device_brand, td.asset_cost, td.entry_date, td.usable_time, td.usable_time_type, td.expiry_date, td.ip_address, td.device_login_pwd, td.location, td.location_desc, td.device_manager_id, u.user_name AS device_manager_name, u.phonenumber, td.device_desc, td.device_image, td.device_qr_code, td.device_state, ( SELECT dict_label FROM sys_dict_data AS dd WHERE dd.dict_type = 'am_device_state' and dd.dict_value = td.device_state ) AS device_state_name, td.previous_device_state, td.create_by, td.create_time, td.update_by, td.update_time, td.remark FROM am_it_device AS td LEFT JOIN am_site AS s ON s.site_id = td.site_id LEFT JOIN sys_user AS u ON u.user_id = td.device_manager_id WHERE td.device_type IN (?) and td.site_id IN (?) and td.device_manager_id IN (?) and td.device_state IN (?) GROUP BY td.device_id ORDER BY td.device_id DESC
11:56:32.667 [http-nio-8103-exec-10] DEBUG c.n.a.m.I.selectItDeviceList - [debug,137] - ==> Parameters: 1,2,3(String), 1(String), 1(String), 1,2,3,4,5(String)
11:56:32.668 [http-nio-8103-exec-10] DEBUG c.n.a.m.I.selectItDeviceList - [debug,137] - <==      Total: 0

解决方法:

在XXXMapper.xml文件(类似于ItDeviceMapper.xml的文件)在里面自定义sql语句代码,给参数要用 ${参数名} 的方式。

            <if test="deviceTypes != null and deviceTypes != '' ">
                and td.device_type IN (${deviceTypes})
            </if>
            <if test="siteIds != null and siteIds != '' ">
                and td.site_id IN (${siteIds})
            </if>
            <if test="deviceManagerIds != null and deviceManagerIds != '' ">
                and td.device_manager_id IN (${deviceManagerIds})
            </if>
            <if test="deviceStates != null and deviceStates != '' ">
                and td.device_state IN (${deviceStates})
            </if>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值