自定义 VDM 对象缺少获取方法
Getters methods missing on custom VDM object
我在 S/4Hana Cloud 中创建了一个自定义业务对象。
自定义对象
然后获取元数据,最后添加到我的java项目中。
现在我需要阅读 table 并将其中的一些字段用于后续逻辑。
我这样检索table:
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"
例如,通过使用列入白名单的 APIs,API.
的每个字段都有 getters
你们能告诉我为什么我在自定义 VDM 对象上看不到 getter 方法吗?
备注:我创建了两个额外的自定义对象,其中 none 个带来了 getters。
添加元数据文件:[删除了字符限制]
添加我的 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>
此外,生成的方法列表:
methods
BR,
彼得罗
我假设您使用生成器根据元数据生成 VDM。如果可以,请分享元数据。
假设如上,您尝试使用的字段不会也不打算保存任何数据。它是在构建 OData 请求时使用的,因此在 select 和过滤操作中。
为了访问数据,您确实需要实体类型的 getter。确保在您的项目中包含 lombok
作为依赖项,因为我们在生成的代码中使用 @Data
annotation:
<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 plugin 以便 linter 和自动完成功能正常工作。
我在 S/4Hana Cloud 中创建了一个自定义业务对象。
自定义对象
然后获取元数据,最后添加到我的java项目中。
现在我需要阅读 table 并将其中的一些字段用于后续逻辑。
我这样检索table:
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"
例如,通过使用列入白名单的 APIs,API.
的每个字段都有 getters你们能告诉我为什么我在自定义 VDM 对象上看不到 getter 方法吗?
备注:我创建了两个额外的自定义对象,其中 none 个带来了 getters。
添加元数据文件:[删除了字符限制] 添加我的 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>
此外,生成的方法列表: methods BR, 彼得罗
我假设您使用生成器根据元数据生成 VDM。如果可以,请分享元数据。
假设如上,您尝试使用的字段不会也不打算保存任何数据。它是在构建 OData 请求时使用的,因此在 select 和过滤操作中。
为了访问数据,您确实需要实体类型的 getter。确保在您的项目中包含 lombok
作为依赖项,因为我们在生成的代码中使用 @Data
annotation:
<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 plugin 以便 linter 和自动完成功能正常工作。