我正在循环列表以从列表数组中获取特定的ID:
这是我正在循环的列表:
for(int i =0 ;i<listOfIds.size();i++) {
System.out.println("list of post_ids " + listOfIds.get(i));
}
循环后输出为:
list of post_ids Model: com.soul.seeker.models.PostsCategories, table: 'posts_categories', attributes: {post_id=184}
list of post_ids Model: com.soul.seeker.models.PostsCategories, table: 'posts_categories', attributes: {post_id=185}
现在我想访问特定元素,即attributes: {post_id=185}
。我该怎么做?
更新:类列表属于http://javalite.github.io/activejdbc/snapshot/
类型LazyList
答案 0 :(得分:1)
我有一个想法,在循环中使用你想要的标准创建新对象,并在你想要的对象和列表中的对象之间使用等于:
for(int i =0 ;i<listOfIds.size();i++) {
my_object obj = new my_object ();
obj.(set criteria you want )
if(listOfIds.get(i).equals(obj)){
"you got it";
}
System.out.println("list of post_ids " + listOfIds.get(i));
}
答案 1 :(得分:1)
由于您在ActiveJDBC型号上运行,您可以:
PostsCategories c;
for(int i =0 ;i<listOfIds.size();i++) {
if(listOfIds.get(i).get("post_id").equals(185))}
c = listOfIds.get(i);
System.out.println("Found it: " + c);
}
}
答案 2 :(得分:0)
实际上API上有方法。我认为这是正常的List
。所以无论如何,我这样想:
List postIds = listOfIds.collect("post_id");
String query2 = "Select * from post Where id IN (";
for(int i =0 ; i < postIds.size(); i++) {
query2 = query2 + "'" +postIds.get(i) + "'" + ",";
}
query2 = query2.substring(0, query2.length()-1);
query2 = query2 + ")";