// 根据传入的字符串查询对应树查询
strings.stream().map( s -> {
List<JSONObject> objects = tClassifiedStructureMapper.selectById( s );
JSONObject jsonObject = objects.get( 0 );
// selectTree是递归调用,查询树
// selectTree可能会返回null
// 返回null时会报空指针异常
List<JSONObject> jsonObjects = new LoginForServiceImpl().selectTree( s );
if (null != jsonObjects && 0 != jsonObjects.size()) {
jsonObject.put( "children", jsonObjects );
}
return jsonObject;
} ).collect( Collectors.toList() );
注:正常使用for循环处理就不会报错
你应该先进行非空判断在进行数据流处理