当表中的id为bigint类型,并且要通过id的数组来查询数据时,此时id的数组不能是字符串数组String[]而应该是Long[],此时就需要将字符串数组转换成Long类型数组

String[] inDetailIdsString = inDetailIdString.split(",");
//string 转为  long
List<Long> inDetailIds = Arrays.stream(inDetailIdsString)
                        .map(s -> Long.parseLong(s.trim())).collect(Collectors.toList());
...
int count4 = inStoreDetailDao.queryCountByCurCodeAndDetailId(inStoreCodeTab, curcode, inDetailIds);

dao接口

int queryCountByCurCodeAndDetailId(@Param("inStoreCodeTab") String inStoreCodeTab, @Param("curcode") String curcode, @Param("inDetailIds") List<Long> inDetailIds);

mapper.xml

<select id="queryCountByCurCodeAndDetailId" resultType="int">
        select count(*) from ${inStoreCodeTab}
        <where>
            <if test="curcode!=null and curcode!=''">
                AND CURCODE = #{curcode}
            </if>
            <if test="inDetailIds!=null and inDetailIds.size()>0">
                <foreach collection="inDetailIds" open=" and IN_DETAIL_ID in( " close=")" item="id" separator=",">
                    #{id}
                </foreach>
            </if>
        </where>
    </select>

 

posted on 2021-09-17 09:50  周文豪  阅读(5043)  评论(0编辑  收藏  举报