Skip to content

Instantly share code, notes, and snippets.

@Felipe00
Last active December 30, 2017 01:07
Show Gist options
  • Save Felipe00/9ba7a6d7bffbd780949bb1e170e914d9 to your computer and use it in GitHub Desktop.
Save Felipe00/9ba7a6d7bffbd780949bb1e170e914d9 to your computer and use it in GitHub Desktop.
Dúvida: Como retornar uma lista de um objeto Foo, com base no type da list Doo?
class Foo {
public static Finder<Long, Foo> find = new Finder<>(Foo.class);
Long id;
String name;
List<Doo> dooList;
/* Retorna uma lista de objetos Foo pelo type de Doo */
public static List<Foo> getAllFoos(String type) {
return Doo.getFooByDooType(type);
}
}
class Doo {
public static Finder<Long, Doo> find = new Finder<>(Doo.class);
Long id;
String type;
Foo foo;
/* RESPOSTA: Buscar todos os Doo's com type escolhido e depois passar os objetos Foo de Doo */
/* Retorna todos os Foo com base no type de Doo */
public static List<Foo> getFooByDooType(String type) {
List<Doo> dooList = find.query().where().eq("type", type).findList();
List<Foo> fooList = new ArrayList<>();
for (Doo obj: dooList) { fooList.add(obj.getFoo()); }
return fooList;
}
}
class FooController {
public Result listAllFoo() {
return ok(Json.toJson(Foo.getAllFoos(1L))); // Funciona! ;)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment