- 实现一:Screem.xml 中的 section 里,加 <action>, 加 get-related
- 实现二:在代码中使用 DynamicViewEntity对象,加入addMemberEntity,addAlias,addViewLink,再用 find 查询
DynamicViewEntity dve = new DynamicViewEntity(); dve.addMemberEntity("TMP", GlobalConstant.TRUST_MALL_PRODUCT_ENTITY_NAME); dve.addAlias("TMP", "productId"); dve.addAlias("TMP", "productCode"); dve.addAlias("TMP", "productName"); dve.addAlias("TMP", "productPrice"); dve.addAlias("TMP", "prodStatus"); dve.addAlias("TMP", "productStandardPrice"); dve.addAlias("TMP", "inventoryStatus"); dve.addAlias("TMP", "productKeywords"); dve.addAlias("TMP", "productDesc"); dve.addAlias("TMP", "prodCreatedBy"); dve.addAlias("TMP", "createdStamp"); dve.addAlias("TMP", "prodModifiedBy"); dve.addAlias("TMP", "lastUpdatedStamp"); dve.addAlias("TMP", "shopId"); dve.addRelation("one", "", "MallProductCategory", UtilMisc.toList(new ModelKeyMap("categoryId", "categoryId"))); dve.addMemberEntity("MPC", "MallProductCategory"); dve.addAlias("MPC", "categoryId"); dve.addAlias("MPC", "sortedName"); dve.addViewLink("TMP", "MPC", false, UtilMisc.toList(new ModelKeyMap("categoryId", "categoryId")));
- 实现三:在 entity.xml 里定义 view-entity 实体对象,在查询时就查这个view的对象
<view-entity entity-name="VShopReview" package-name="com.ufinity.trustmall"> <member-entity entity-alias="SR" entity-name="ShopReview"></member-entity> <member-entity entity-alias="TMUI" entity-name="TrustMallUserInfo"></member-entity> <member-entity entity-alias="TMS" entity-name="TrustMallShop"></member-entity> <member-entity entity-alias="SRR" entity-name="ShopReviewReported"></member-entity> <alias-all entity-alias="SR"/> <alias name="shopReviewId" entity-alias="SR" group-by="true"/> <alias name="userName" entity-alias="TMUI"/> <alias name="shopName" entity-alias="TMS"/> <alias name="createdStamp" entity-alias="SR"/> <alias name="reporterId" entity-alias="SRR" field="userId" col-alias="userId"/> <view-link entity-alias="SR" rel-entity-alias="TMUI"> <key-map field-name="userId" rel-field-name="userId"/> </view-link> <view-link entity-alias="SR" rel-entity-alias="TMS"> <key-map field-name="shopId" rel-field-name="shopId"/> </view-link> <view-link entity-alias="SR" rel-entity-alias="SRR" rel-optional="true"> <key-map field-name="shopReviewId" rel-field-name="shopReviewId"/> </view-link> </view-entity>