首页 > 解决方案 > 自定义 VDM 对象上缺少 Getter 方法

问题描述

我在 S/4Hana Cloud 中创建了一个自定义业务对象。

自定义对象 截屏

然后获取元数据,最后添加到我的java项目中。

现在我需要阅读表格并将一些字段用于后续逻辑。

我以这种方式检索表:

cockpitSetupList = new DefaultCscCockpitSetupService().getAllCSCCOCKPIT_SETUP()
                    .orderBy(CSCCOCKPIT_SETUP.COCKPIT_TYPE, Order.ASC)
                    .execute();

我想读取字段的值,所以我循环它并读取字段值,如下所示:

for (CSCCOCKPIT_SETUP cockpitsetup : allCockpitSetup) {

// read all the product for the sales Organization sent from cockpit setup
    String salesOrganizationInString = 
    String.valueOf(cockpitsetup.SALES_ORGANIZATION);
    allProductsPerSalesOrganization = products.getAllProductSalesPerSalesOrganization(salesOrganizationInString);

但是,它没有给出该字段的值,而是类似:

"com.sunstar.vdm.namespaces.csccockpitsetup.field.CSCCOCKPIT_SETUPField@d6ba2449"

例如,通过使用列入白名单的 API,我为 API 的每个字段设置了 getter。

你们能告诉我为什么我在自定义 VDM 对象上看不到 getter 方法吗?

备注:我已经创建了两个额外的自定义对象,它们都没有带来 getter。

添加元数据文件:[删除到字符限制]添加我的 POM 文件:

    <dependencies>
        <dependency>
            <groupId>com.sap.cloud.s4hana.cloudplatform</groupId>
            <artifactId>scp-neo</artifactId>
        </dependency>
        <dependency>
            <groupId>com.sap.cloud.s4hana</groupId>
            <artifactId>s4hana-all</artifactId>
        </dependency>
       <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.sap.cloud</groupId>
            <artifactId>neo-javaee7-wp-api</artifactId>
            <scope>provided</scope>
        </dependency>
         <dependency>
            <groupId>org.thymeleaf</groupId>
            <artifactId>thymeleaf</artifactId>
            <version>3.0.0.RELEASE</version>
        </dependency>
<!--        commented out to get VDM getters -->
<!--         <dependency>-->
<!--            <groupId>org.projectlombok</groupId>-->
<!--            <artifactId>lombok</artifactId>-->
<!--            <scope>provided</scope>-->
<!--        </dependency>-->
        <dependency>
            <groupId>org.modelmapper</groupId>
            <artifactId>modelmapper</artifactId>
            <version>1.1.2</version>
        </dependency>
<!--    custom VDM-->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>
<!--     custom VDM   -->
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencies>

此外,生成的方法列表: 方法 BR、Pietro

标签: javasap-cloud-sdk

解决方案


我假设您使用生成器根据元数据生成 VDM。如果可能的话,请分享元数据。

假设上述情况,您尝试使用的字段不会也不打算保存任何数据。它在构建 OData 请求时使用,因此在选择和过滤操作中使用。

为了访问数据,您确实需要实体类型的 getter。当我们在生成的代码中使用注释时,请务必lombok在您的项目中包含依赖项:@Data

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <scope>provided</scope>
</dependency>

我在本地生成了代码,我看到注释存在于实体上。所以应该有吸气剂存在。我设置了一个小项目,并编译了以下代码:

final CSCCOCKPIT_SETUP setup = new CSCCOCKPIT_SETUP();
final String salesOrganization = setup.getSalesOrganization();

如果您在 IDE 中看不到这些方法,您可能需要安装或启用lombok 插件才能使 linter 和自动完成功能正常工作。


推荐阅读