简体   繁体   English

如何从资源包/属性文件的值中读取键

[英]How to read key from value of resource bundle/properties file

I have messages.properties bundle file which contains labels in key, value pair like我有messages.properties捆绑文件,其中包含键、值对中的标签,例如

meta.enum.ShipmentStatus.Loaded=Loaded

But I want read key from value ie from user/client view I get "Loaded" value and I want read key of that value ie "meta.enum.ShipmentStatus.Loaded".但我想从值中读取键,即从用户/客户端视图我得到“加载”值,我想读取该值的键,即“meta.enum.ShipmentStatus.Loaded”。

How to achieve this?如何做到这一点?

You can read keys by loading all keys and values into a map.您可以通过将所有键和值加载到 map 来读取键。 If so,如果是这样,

public <K, V> Stream<K> keys(Map<K, V> map, V value) {
return map
  .entrySet()
  .stream()
  .filter(entry -> value.equals(entry.getValue()))
  .map(Map.Entry::getKey); }

can return the keys for the value.可以返回值的键。 But, if you are using Spring look at: https://stackoverflow.com/a/34655571/11813364但是,如果您使用的是 Spring,请查看: https://stackoverflow.com/a/34655571/11813364

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从属性文件/资源​​束中键值中动态插入的数字中删除逗号? - How to remove comma from a number being dynamically inserted in the value of a key in the properties file / resource bundle? 如何从Excel文件(xlsx)读取2列并将其作为键=值对写入资源属性 - How to read 2 columns from excel file (xlsx) and write it to resource properties as key=value pair 使用资源包从属性文件中读取日语字符 - Read Japanese Characters from a properties file using Resource Bundle 资源束属性文件的替代 - Alternative to resource bundle properties file 如何使用java从资源文件中读取属性 - How to read properties from resource file using java 如何在Java代码块(jsp文件)中访问spring资源束键/值 - How can I access spring resource bundle key/value in a java code block (jsp file) 我如何从包中读取文件-类似于Java中的资源包 - How do I read a file from a package - something like a resource bundle in Java 如何从 Java 中的文件资源加载资源包? - How to load a resource bundle from a file resource in Java? 如何从JavaScript文件中的属性文件中读取值 - How to read a value from properties file in a javascript file 如何从属性文件中读取值并放入 JSON 文件 - How read value from properties file and put into JSON file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM