服务构建器 Liferay 关系
Service Builder Liferay Relationships
我有 "Storage" 个 portlet:
我可以点击"Add Book":
但我需要有机会在我的书中添加作者的名字。所以我创建了新项目,新的 Service Builder 和新的实体 "author",现在我也可以添加作者了。但是,当我单击 "add book" 时,如何使用现有作者制作下拉菜单?我如何将该字段与新的 table - "author" 绑定?
您不需要为作者创建另一个项目,在与书籍实体相同的服务构建器中添加作者实体并添加对另一个 table 的引用,该引用将保存书籍和作者的主键.
service.xml
可能是:
<service-builder package-path="com.myproject.db">
<author>SO</author>
<namespace>myp</namespace>
<entity name="Book" local-service="true" remote-service="true" cache-enabled="false">
<column name="bookId" type="long" primary="true" />
<column name="name" type="String" />
<column name="description" type="String" />
<column name="price" type="long" />
<column name="author" type="Collection" entity="Author" mapping-table="Author_Books"/>
</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="Author_Books" />
</entity>
</service-builder>
当您部署此 portlet 时,它将创建另一个 table myp_Author_Books
,它将具有 authorId
和 bookId
的复合键。
比在你的书本形式的渲染方法中添加
List<Author> authorList=AuthorLocalServiceUtil.getAuthor(0, AuthorLocalServiceUtil.getAuthorCount());
renderRequest.addAttribute("listAuthor",authorList )
并在 jsp 中将此属性与 c:forEach
和 aui:select
一起使用来创建您的下拉列表,如下所示:
<aui:select name="author" label="Author Name">
<c:forEach var="currAuthor" items="${listAuthor}">
<aui:option value="${currAuthor.authorId}" label=" ${student.authorName}"></aui:option>
</c:forEach>
</aui:select>
我有 "Storage" 个 portlet:
我可以点击"Add Book":
但我需要有机会在我的书中添加作者的名字。所以我创建了新项目,新的 Service Builder 和新的实体 "author",现在我也可以添加作者了。但是,当我单击 "add book" 时,如何使用现有作者制作下拉菜单?我如何将该字段与新的 table - "author" 绑定?
您不需要为作者创建另一个项目,在与书籍实体相同的服务构建器中添加作者实体并添加对另一个 table 的引用,该引用将保存书籍和作者的主键.
service.xml
可能是:
<service-builder package-path="com.myproject.db">
<author>SO</author>
<namespace>myp</namespace>
<entity name="Book" local-service="true" remote-service="true" cache-enabled="false">
<column name="bookId" type="long" primary="true" />
<column name="name" type="String" />
<column name="description" type="String" />
<column name="price" type="long" />
<column name="author" type="Collection" entity="Author" mapping-table="Author_Books"/>
</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="Author_Books" />
</entity>
</service-builder>
当您部署此 portlet 时,它将创建另一个 table myp_Author_Books
,它将具有 authorId
和 bookId
的复合键。
比在你的书本形式的渲染方法中添加
List<Author> authorList=AuthorLocalServiceUtil.getAuthor(0, AuthorLocalServiceUtil.getAuthorCount());
renderRequest.addAttribute("listAuthor",authorList )
并在 jsp 中将此属性与 c:forEach
和 aui:select
一起使用来创建您的下拉列表,如下所示:
<aui:select name="author" label="Author Name">
<c:forEach var="currAuthor" items="${listAuthor}">
<aui:option value="${currAuthor.authorId}" label=" ${student.authorName}"></aui:option>
</c:forEach>
</aui:select>