访问接口返回数据类型为List<List<model>>,现在想将其中的model插入数据库,感觉一点点循环有点傻,0.0...,各位有没有其他的方法?
访问接口返回数据类型为List<List<model>>,现在想将其中的model插入数据库,感觉一点点循环有点傻,0.0...,各位有没有其他的方法?
public static IEnumerable<T> GetItems<T>(this List<List<T>> list)
{
foreach (var child in list)
{
foreach (var item in child)
{
yield return item;
}
}
}
public static IEnumerable<T> GetNestItems<T>(this System.Collections.IList list)
{
Type type = null;
foreach (var item in list)
{
if (type == null) type = item.GetType();
if (type == typeof(T))
{
yield return (T)item;
}
else if (type.GetGenericTypeDefinition() == typeof(List<>))
{
var items = GetNestItems<T>((System.Collections.IList)item);
foreach (var t in items)
{
yield return t;
}
}
}
}
4 回答1.3k 阅读✓ 已解决
4 回答1.2k 阅读✓ 已解决
1 回答2.6k 阅读✓ 已解决
2 回答724 阅读✓ 已解决
2 回答1.7k 阅读
2 回答1.7k 阅读
2 回答1.3k 阅读
list.stream().flatMap(model-> model.stream()).forEach(System.out::println);