我想做下面的事情,但是代码效率低下,
如何返回相关对象的分页响应?
System.out.println("Title: ");
String i = in.nextLine();
title.add(i);
try{
FileWriter fw = new FileWriter("C:\\title.txt");
for(String de: title){
fw.write(de + System.lineSeparator());
}
fw.close();
}catch(Exception e){ System.out.println(e);}
System.out.println("Sucess..");
}
答案 0 :(得分:0)
实际上我在这里https://stackoverflow.com/a/37657376/433570
找到了答案想法是平整嵌套对象
class FooSerializer():
bar = BarSerializer()
def to_representation(self, obj):
"""Move fields from profile to user representation."""
representation = super().to_representation(obj)
profile_representation = representation.pop('bar')
for key in profile_representation:
representation[key] = profile_representation[key]
return representation