场景
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是
之后我想循环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()));
{{item.user_info.nickname ? item.user_info.nickname : item.user_name}}
作者 管理员 企业
{{itemf.name}}
{{itemc.user_info.nickname}}
{{itemc.user_name}}
回复 {{itemc.comment_user_info.nickname}}
{{itemf.name}}