我需要导出模型的一些实例,但我不想要全部。我只需要具有特定属性的那个。
我可以通过代码做到这一点,我想知道如何用 Impex 做到这一点?
您可以通过其他方式导出实例:
步骤1 :
转到 HMC 界面,选择 script generator tool System->Tools->Script Generator
,然后生成 ImpEx 脚本模型,然后选择要导出的实例类型脚本,例如:
"#% impex.setTargetFile( ""Customer.csv"" );" // 1. where to export
insert_update Customer;&Item;@password[translator=de.hybris.platform.impex.jalo.translators.UserPasswordTranslator];CN;CodeNaf(code);DN;Europe1PriceFactory_UDG(code,itemtype(code));Europe1PriceFactory_UPG(code,itemtype(code));Europe1PriceFactory_UTG(code,itemtype(code));accountOrigine(&Item);accountVerificationType;addresses(&Item);authentificationDate[dateformat=dd.MM.yyyy hh:mm:ss];authorizedToUnlockPages[allownull=true];birthDate[dateformat=dd.MM.yyyy hh:mm:ss];carts(code);codeAPE;codeRCS;codeSiret;company;companyType(code,itemtype(code));creationtime[forceWrite=true,dateformat=dd.MM.yyyy hh:mm:ss];customerID;dateOfBirth[dateformat=dd.MM.yyyy hh:mm:ss];defaultPaymentAddress(&Item);defaultPaymentInfo(&Item);defaultShipmentAddress(&Item);description;domain;emailAlias;encodedPassword;enseigne(code)[allownull=true];erosId;europe1Discounts(&Item);firstname;fraudStatus(code,itemtype(code));hmcLoginDisabled;interestAreaList(code,itemtype(code));isprofessionnel;lastLogin[dateformat=dd.MM.yyyy hh:mm:ss];lastname;ldapaccount[allownull=true];ldaplogin;ldapsearchbase;locationType(code,itemtype(code));loginDisabled[allownull=true];modifiedtime[dateformat=dd.MM.yyyy hh:mm:ss];name;nbChild;nbGodSon;orders(code,versionID);origin;originalUid;owner(&Item)[allownull=true];password;passwordAnswer;passwordEncoding;passwordQuestion;paymentInfos(&Item);previewCatalogVersions(catalog(id),version);profilePicture(catalogVersion(catalog(id),version),code);recevedDocs;sessionCurrency(isocode);sessionLanguage(isocode);subscriptionTelContact(&Item);title(code);token;type(code,itemtype(code));uid[unique=true,allownull=true];userprofile(&Item);verificationDate[dateformat=dd.MM.yyyy hh:mm:ss];verificationflag // 2. how to export
"#% impex.exportItems( ""Customer"" , false );" // 3. what to export
为了增加您所寻找的内容,我将重点关注第 3 行
#% impex.exportItems( ""Customer"" , false );" // 3. what to export
因此,您可以通过不同的方式使用exportItems方法:
按项目集导出项目:
public void exportItems( Collection<Item> items )
public void exportItems( String[] pklist )
这些方法导出给定项目,其中项目可以作为 PK(字符串)列表传递,也可以直接用作项目集合。
exportItems按类型代码:
public void exportItems( String typecode )
public void exportItems( String typecode, int count )
public void exportItems( String typecode, boolean inclSubTypes )
public void exportItems( String typecode, int count, boolean inclSubTypes )
通过 FlexibleSearch导出项目:
public void exportItemsFlexibleSearch( String query )
public void exportItemsFlexibleSearch( String query, Map values, List resultClasses, final boolean failOnUnknownFields, final boolean dontNeedTotal, int start, int count )
public void exportItemsFlexibleSearch( String query, int count )
注意:默认情况下,Exporter API 使用搜索结果的分页。因此,要获得准确的结果,您的 FlexibleSearch 查询必须包含ORDER BY
子句示例:
impex.exportItemsFlexibleSearch(""select {PK} from {Customer} where {uid}='anonymous' ORDER BY {pk}"")
如果您有权访问 help.hybris,请检查:
如果您只能访问 wiki:
第 2 步:
转到 HAC 界面,ImpEx Export
然后输入您的脚本并导出您的项目。
我可以从后台 -> 工具 -> 生成的脚本生成导出模型。
然后我可以添加一个灵活的搜索查询来过滤导出的结果:
# ---- Extension: core ---- Type: Customer ----
"#% impex.setTargetFile( ""Customer.csv"" );"
insert_update Customer;&Item;Europe1PriceFactory_UDG(code,itemtype(code));Europe1PriceFactory_UPG(code,itemtype(code));Europe1PriceFactory_UTG(code,itemtype(code));allowSubstitution[allownull=true];...
"#% impex.exportItemsFlexibleSearch(""select {PK} from {Customer} where {uid}='anonymous'"", Collections.EMPTY_MAP, Collections.singletonList( Item.class ), true, true, -1, -1 );"