我知道我已经问过这个问题,但我还有误解。我之前的问题: Liferay 和其中的关系
简而言之:我有一个 portlet,它可以添加/更新/删除书籍和添加作者。此外,您可以在尝试添加书籍时选择现有作者。
http://i.stack.imgur.com/vzUjn.png
现在我需要在“作者”表中显示每个作者写了多少本书。
我的服务.xml:
<entity name="Book" local-service="true" remote-service="true" cache-enabled="false">
<column name="bookId" type="long" primary="true" />
<column name="bookName" type="String" />
<column name="bookDescription" type="String" />
<column name="authors" type="Collection" entity="Author" mapping-table="Books_Authors" />
<finder return-type="Collection" name="bookName">
<finder-column name="bookName"></finder-column>
</finder>
</entity>
<entity name="Author" local-service="true" remote-service="true" cache-enabled="false">
<column name="authorId" type="long" primary="true" />
<column name="authorName" type="String" />
<column name="books" type="Collection" entity="Book" mapping-table="Books_Authors" />
</entity>
我应该创建什么查找器来实现我的目标?如果我创建 bookName finder,我可以计算我有多少不同的书。如果我创建 authorName finder,我可以计算我有多少作者。我有点失落。
感谢您的帮助,但我仍有一些问题:
authorName
我如何以及在哪里可以获得authorId
?如何
count
在我的表中使用我的变量view.jsp
?long count = BookLocalServiceUtil.countByAuthor(authorId);
public void addBook(ActionRequest actionRequest, ActionResponse actionResponse)
throws IOException, PortletException {
String bookName = ParamUtil.getString(actionRequest,"bookName");
String bookDescription = ParamUtil.getString(actionRequest, "bookDescription");
Long authorId = ParamUtil.getLong(actionRequest, "author");
try {
Book book = BookLocalServiceUtil.createBook(CounterLocalServiceUtil.increment());
book.setBookName(bookName);
book.setBookDescription(bookDescription);
book.setAuthorId(authorId);
book=BookLocalServiceUtil.addBook(book);
String author = ParamUtil.getString(actionRequest, "authorId");
} catch (Exception e) {
log.info(ADD_BOOK_ERROR, e);
SessionErrors.add(actionRequest, "PortalExceptionError");
}
}