Author
(Cursor 1 Data)
ID | NAME | PUBLISH_ID |
---|---|---|
1 | John | 123 |
2 | Jane | 345 |
Book
(Cursor 2 Data)
PUBLISH_ID | BOOK_ID | BOOK_NAME |
---|---|---|
123 | B101 | C# |
123 | B102 | Python |
345 | J001 | SQL |
345 | J002 | JAVA |
Class Author {
String Id
String authName;
List<Books> books
}
Class Books {
int publishId;
int bookId;
String bookName;
}
Question: how can it be mapped so that author can have only their books and want to display each author with their own books only?
I tried: there are two separate cursors Author
and Books
. I will have to use mybatis xmlconfig mapper. I can't use a query to achieve only mybatis mapper config xml
Map I tried shown here doesn't work:
<resultMap id="authorMap type="demo.Author">
<id property="Id" column="Id"></id>
<collection property="Books" column="publishId" type="ArrayList" resultMap="booksMap" />
</resultMap>
<resultMap id="booksMap" type="demo.Books">
<result property="publishId" column="publish_id"/>
<result property="bookId" column="book_id"/>
</resultMap>
I'm expecting to map base on publish id so each author only their multiple books.
Id:1
authNm: John
Email: John@g.com
book:
publishId: 123,
bookId: B101
publishId: 123,
bookId: B102
Id:2
authNm:Jane
book:
publishId: 345,
bookId: J001
publishId: 345,
bookId: J002`