Hybris Item:custom-属性 和 attributes 的区别

Hybris Item: difference between custom-property and attributes

在 hybris 类型的定义中,我遇到了难以理解这两个标签的含义的问题:

详细来说,第一个包含子标签 <属性>,第二个包含子标签 。在 "property" 标签中还有一个带有内容的标签

我所依据的示例代码取自hybris trail,即:

<itemtype
    code="News"
    autocreate="false"
    generate="false">
    <custom-properties>
        <property name="catalogItemType"><value>java.lang.Boolean.TRUE</value></property>
        <property name="catalogVersionAttributeQualifier"><value>"catalogVersion"</value></property>
        <property name="uniqueKeyAttributeQualifier"><value>"id"</value></property>
    </custom-properties>
    <attributes>
        <attribute qualifier="id" type="java.lang.String">
            <modifiers initial="true" optional="false" write="true"/>
            <persistence type="property"/>
            </attribute>
        <attribute qualifier="catalogVersion" type="CatalogVersion">
            <modifiers initial="true" optional="false" write="true"/>
            <persistence type="property"/>
        </attribute>
    </attributes>
</itemtype>

总的来说, 这两个标签有什么区别?

<custom-properties>
    <property name="catalogItemType">
        <value>java.lang.Boolean.TRUE</value>
    </property>
    <property name="catalogVersionAttributeQualifier">
        <value>"catalogVersion"</value>
    </property>
    <property name="uniqueKeyAttributeQualifier">
        <value>"code"</value>
    </property>
</custom-properties>

这些 <custom-properties> 用于将 ItemType 定义为目录感知。喜欢产品类型。您可以参考this post了解更多详情。

<attribute>用于定义和配置table/item的列。

在SQL这个词中,我可以说<custom-properties>用于table级别配置(元数据),而<attribute>用于定义和配置该列table.

项目属性定义项目的状态。它们实际上是作为平台构建和更新过程的结果而创建的数据库 table 的列(动态属性除外)。

自定义属性是某些已定义的属性,它们在类型系统定义中用于定义类型的某些属性。通常,如果您解释类型系统的元数据,您可能会读取属性以实现所需的行为。它们可以在不同级别定义

  1. 在项目类型级别 - 自定义属性用于定义类型的属性。这是您在问题正文中发布的示例。问题中的自定义类型

<custom-properties>
        <property name="catalogItemType"><value>java.lang.Boolean.TRUE</value></property>
        <property name="catalogVersionAttributeQualifier"><value>"catalogVersion"</value></property>
        <property name="uniqueKeyAttributeQualifier"><value>"id"</value></property>
    </custom-properties>

这些属性是在类型级别定义的 - 这些属性在类型级别提供目录意识。这些属性可以在运行时通过 getProperty( String 属性Name ) 方法检索这些项目类型属性还有其他示例。

  1. 关系等级,请看下面的片段

<relation code="User2Addresses" generate="true" localized="false" autocreate="true">
    <sourceElement type="User" cardinality="one" qualifier="owner">
        <modifiers read="true" write="true" search="true" optional="true" initial="false"/>
    </sourceElement>
    <targetElement type="Address" cardinality="many" qualifier="addresses">
        <modifiers read="true" write="true" search="true" optional="true" partof="true"/>
        <custom-properties>
            <property name="condition.query">
                <value>"{original} is null"</value>
            </property>
        </custom-properties>
    </targetElement>
</relation>

属性 保存一个字符串,该字符串稍后添加到为一对多或多对一关系生成的 select 查询的 'where' 部分。

  1. 排序属性 - 通过定义ordering.attribute,可以指定在从数据库
  2. 中检索时使用哪个属性对多边项进行排序

<relation code="AbstractOrder2AbstractOrderEntry" localized="false" generate="true" autocreate="true">
   <sourceElement type="AbstractOrder" qualifier="order" cardinality="one">
    <modifiers read="true" write="true" search="true" optional="true" />
    <custom-properties>
     <property name="ordering.attribute">
      <value>"entryNumber"</value>
     </property>
    </custom-properties>
   </sourceElement>
   <targetElement type="AbstractOrderEntry" qualifier="entries" cardinality="many" collectiontype="list" ordered="false" >
    <modifiers read="true" write="true" search="true" optional="true" partof="true" />
   </targetElement>
  </relation>

  1. 后台自定义属性- Backoffice 将允许显示任何类型的所有属性(开箱即用),但是有一些特殊的(比方说技术)属性绝对不应该在 UI 中可见,或者至少应该在 UI(不管他们有什么访问权限)。对于那些非常罕见的情况,hybris 引入了两个自定义属性,我们会在扫描类型系统时解释这些属性

<property name="readOnlyForUI">
     <value>Boolean.TRUE</value>
 </property>
 <property name="hiddenForUI">
     <value>Boolean.TRUE</value>
 </property>

希望对您有所帮助!