Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java ActiveJDBC从多个表中选择_Java_Activejdbc - Fatal编程技术网

Java ActiveJDBC从多个表中选择

Java ActiveJDBC从多个表中选择,java,activejdbc,Java,Activejdbc,我想从多个表中进行选择,并使用ActiveJDBC将结果转换为json 我可以执行以下操作,但它当然只返回模型书中的列,我看不到作者模型中的列。如何才能做到这一点 LazyList<Book> book = Book.findBySQL("select books.*, authors.* from books, authors where books.author_id = author.id"); jsonOutput = book.toJson(true); LazyLis

我想从多个表中进行选择,并使用ActiveJDBC将结果转换为json

我可以执行以下操作,但它当然只返回模型书中的列,我看不到作者模型中的列。如何才能做到这一点

LazyList<Book> book = Book.findBySQL("select books.*, authors.* from books, authors where books.author_id = author.id");
jsonOutput = book.toJson(true);
LazyList book=book.findBySQL(“从books中选择books.*,authors.*,authors where books.author\u id=author.id”);
jsonOutput=book.toJson(true);

首先,您显然有一对多的关联,因此不需要使用
findBySQL()
。当框架无法提供帮助,但您的案例是标准案例时,可以使用此方法。 根据本页:以及本页: 你需要这样写:

LazyList<Author> authors = Author.findAll().include(Book.class);
String json = authors.toJson(true);
当然,这会将所有作者及其作品载入内存。您可能希望使用适当的条件将
Author.findAll()
替换为
Author.where(..)


我希望这有帮助

是的,但如果我有一个复杂的查询,从多个表中提取图书作者出版商等。。。没有办法做到这一点?我只想从多个表中执行一个通用的select*在这种情况下,您不能使用模型,因为它们是ORM-对象到关系的映射:)。我建议您查看或注意
findAll()
all()
将把整个结果集加载到您的列表(堆)中,而
find()
将允许您以游标的形式一次流式处理数百万条记录。
String json = Author.findAll().include(Book.class).toJson(true);