字符串数组String[]转换成Long类型数组Long[]


当表中的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>

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM