回到主页

slick中取json对象为空报错问题

A server error occurred: Read NULL value (null) for ResultSet column <computed>

· scala,slick
由于在for循环中,查找起来费了点时间。     def userPrivQuery(peid: Long) = { val now = OffsetDateTime.now().toEpochSecond db.run { for { adminClc <- repoDao.Privilege.filter(_.peid === peid).filter(_.prLevel === adminClc.value).exists.result adCity <- repoDao.Privilege.filter(_.peid === peid).filter(_.prLevel === adCity.value).map(_.prTheme.+>>("city")).result orPay <- repoDao.Privilege.filter(_.peid === peid).filter(_.prLevel === PriSys.value) .join(repoDao.OrgPayData.filter(_.timestampStart < now).filter(_.timestampEnd > now)) .on(_.orid === _.orgId).map(_._2.city).result // adList = if(adCity.isEmpty){List("")}else{adCity} ciids <- repoDao.City.filter(_.ciName === adCity.toList.bind.any).map(_.id).result } yield { (adminClc, ciids, orPay) } } }
broken image

从数据中必填的jsonb的字段中取对象,(+>>取出来的对象变成字符串),但是如果根本没有这个对象,执行到上面这句时会出错(for循环中会出错,不在循环中不确定)。

使用这个方法会报A server error occurred: Read NULL value (null) for ResultSet column <computed>这个错误。

最后的解决方法,在取出对象后加.toString(),如图圈出来的所示。

取出来没有这个对象也不会报错,后面按照空数组(List())来使用也没问题。

 

总结:问题小到细枝末节,没有实际遇到很难去发现。需要尝试不同的解决方式。