字符串數組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