You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Java如何从Map对象获取指定字段值并设置制造商价格代码

问题解决:从Map中正确获取制造商价格代码

你当前代码里的ipcToMFPNameMap.getClass().getName()完全是在拿Map的类名称,这肯定不对,你要做的是根据当前ItemPriceCode的priceCode作为键,从Map里取出对应的ManufacturerPriceCodes对象,再提取里面的制造商价格代码字段。

修改步骤:

  • 先获取当前ipcs的priceCode作为查询Map的key
  • 用key从Map中取出对应的ManufacturerPriceCodes实例
  • 做非空判断避免空指针,再提取目标字段值设置给ipcs

修改后的循环代码:

for (ItemPriceCode ipcs : itemPriceCodes) {
    // 获取当前ItemPriceCode的priceCode作为Map的key
    String priceCodeKey = ipcs.getPriceCode();
    // 从Map中取出对应的ManufacturerPriceCodes对象
    ManufacturerPriceCodes mpcEntry = ipcToMFPNameMap.get(priceCodeKey);
    // 非空判断后,设置正确的制造商价格代码(替换getManufacturerPriceCode()为你实际的字段方法名)
    if (mpcEntry != null) {
        ipcs.setManufacturerPriceCode(mpcEntry.getManufacturerPriceCode());
    } else {
        // 可选:无匹配记录时设置默认值或跳过
        ipcs.setManufacturerPriceCode(null);
    }
}

注意:请把代码里的mpcEntry.getManufacturerPriceCode()替换为你实际需要的字段对应的getter方法,比如如果ManufacturerPriceCodes中存储目标价格代码的字段是targetPriceCode,就改成mpcEntry.getTargetPriceCode()。

内容的提问来源于stack exchange,提问作者Njena

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 12:40:25