字符串数组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>

 

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

上一篇:springboot36-thymeleaf字符串拼接


下一篇:SpringBoot扩展接口- BeanFactoryPostProcessor后置处理器