java.math.BigInteger cannot be cast to java.lang.Long错误的解决方案

管理 管理 编辑 删除

场景

mysql数据库中

字段为`authority_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '权限ID',

问题


public interface BmRoleAuthorityRepository extends JpaRepository{
 
@Query(value = "SELECT authority_id FROM bm_role_authority where role_id = ?1", nativeQuery = true)
List getAllAuthorityIdByRoleId(Long roleId);

直接执行,获取到的List是

b1398202305171713099604.png

之后我想循环authorityIdList

for (Long authorityId : authorityIdList) {

结果报错:

java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long

解决方案

没有看到有什么特别好的方法,只能将BigInterger的List先转换为String,然后再转换为Long List

 
List authorityIdList = bmRoleAuthorityRepository.getAllAuthorityIdByRoleId(roleId);
 
if(authorityIdList == null || authorityIdList.isEmpty()) {
   authorityIdList = new ArrayList<>();
}
String idArray = JSONArray.toJSONString(authorityIdList);

之后再处理这个String,将其转换为Long list

 
// [1,2,3] convert to String[]
String[] split = StringUtils.split(StringUtils.substring(allAuthorityIdByRoleId, 1,
        allAuthorityIdByRoleId.length() - 1), ",");
// guava 将String[] convert to Long[]
authorityIdList.addAll(Lists.transform(Arrays.asList(split), Longs.stringConverter()));


CRMEB-慕白寒窗雪 最后编辑于2023-05-17 17:14:01

回复({{post_count}})
回复从新到旧

{{item.user_info.nickname ? item.user_info.nickname : item.user_name}} 作者 管理员 企业

{{item.user_info.title}}
{{item.created_at}}  {{item.user_info.ip_address}}
{{item.like_count}}
{{item.showReply ? '取消回复' : '回复'}}
删除
回复

{{itemc.user_info.nickname}}

{{itemc.user_name}}

作者 管理员 企业

回复 {{itemc.comment_user_info.nickname}}

{{itemc.created_at}}   {{itemc.user_info.ip_address}}
{{itemc.like_count}}
{{itemc.showReply ? '取消回复' : '回复'}}
删除
回复
查看更多
回复
添加回复 ({{post_count}})
129
{{like_count}}
{{collect_count}}

相关推荐

CRMEB-慕白寒窗雪 管理员
社区运营专员---高冷のBoy | 呆萌のGirl

回答

743

发布

1075

经验

20496

快速安全登录

使用微信扫码登录
经验说明

1、发布新帖子,每发布一条帖子可获得20个经验,每天最多可获取200个经验;

2、发布新回复,每发布一条回复可获得10个经验,每天最多可获取200个经验;

3、发布的帖子被管理员设置为精华帖,每被加精一次可获得10个经验,无上限;

4、发布帖子被回复一条,加2个经验,无上限;

5、发布帖子被点赞一个或发布评论被点赞加5个经验,无上限;

6、论坛首页大神积分排行榜,统计90天以内获取的累积经验值进行排序。

7、技术社区经验和官方商城用户经验同步,累计经验值会提升商城会员等级,购买官方商城产品享受对应会员等级折扣

确定
{{item.label}} 首页头条 首页动态 加精 板块推荐 取 消 确 定
回复

快速安全登录

使用微信扫码登录
CRMEB客服

CRMEB咨询热线 咨询热线

400-8888-794

微信扫码咨询

CRMEB开源商城下载 开源下载 CRMEB官方论坛 帮助文档
返回顶部 返回顶部
CRMEB客服