java - 自定义 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
解决方案
我假设您使用生成器根据元数据生成 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 和自动完成功能正常工作。
推荐阅读
- c# - 为什么客户端无法使用 NetMQ 框架从服务器接收消息?
- python - 日期格式并包括天数
- node.js - 杀死由 NodeJs 中的 spawn 触发的 FFmpeg 进程
- java - 声纳规则:符号和符号类型始终未知
- vb.net - 如何使用 linq 从 vb.net 中的键值对列表中的匹配键中获取值?
- python - AttributeError:“模块”对象没有属性错误
- python - 对 Incapsula 保护的网站进行网络抓取?
- json - 计算 JSON 中的键
- dialogflow-es - 使用 Dialogflow 进行出站语音呼叫
- python - Python:我可以在另一个函数中调用一个函数作为 *args 列表的一部分吗?