Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何仅替换列表中的特定值_Java_List_Hibernate - Fatal编程技术网

Java 如何仅替换列表中的特定值

Java 如何仅替换列表中的特定值,java,list,hibernate,Java,List,Hibernate,下面的方法使用hibernate查询将一个表放入名为prefixApplyList的列表中。现在,我只想在返回该列表之前对名为prefix的特定属性进行解密。如何调用该列表中存在的属性前缀的解密方法 public List getPrefixMasterList() { if (prefixMasterList == null) { prefixMasterList = getBaseAppService().find("PrefixMaster.list");

下面的方法使用hibernate查询将一个表放入名为prefixApplyList的列表中。现在,我只想在返回该列表之前对名为prefix的特定属性进行解密。如何调用该列表中存在的属性前缀的解密方法

    public List getPrefixMasterList() {
    if (prefixMasterList == null) {
        prefixMasterList = getBaseAppService().find("PrefixMaster.list");
    }
    return prefixMasterList;
   }
在return语句之前遍历prefixMasterList,您将逐个获得元素

获取元素并解密它

for(PrefixMaster pm : prefixMasterList){
    pm.setPrefix(decryptMethod(pm.getPrefix()));
}

我找到了解决办法。当我使用迭代器时,它工作得很好。希望它能帮助别人

Iterator itr = prefixMasterList.iterator();
        while(itr.hasNext()){
            PrefixMaster pm = (PrefixMaster) itr.next();
            pm.setPrefix(decrypt(pm.getPrefix()));
        }

你可以在列表上迭代,检查列表的属性并解密。我已经添加了截图。现在,您可以解释如何执行此操作。请尝试类似forPrefixMaster l:prefixMasterList{l.setPrefixdecryptl.getPrefix;}prefixMasterList显示一个名为类型不匹配的错误:无法从元素类型对象转换为prefixMasterList您确定prefixMasterList是List吗?如果是,则不应发生不匹配,如果不是,则尝试将其更改为Listoutside循环,尝试此列表prefixMasters=ListprefixMasterList;然后迭代PrefixMaster。现在我只对PrefixMasterBean使用加密和解密。还有很多其他的大师。因此,除了在每个bean中使用加密和解密方法外,还有其他简单的方法可以做到这一点。一般的意思是有什么方法可以做到这一点吗@外星人