读取配置文件,序列化为对象数组, 用这种方式可以大量精细化控制一些操作。。。。。。。。。。。。。。。。。。。
@Component
@Slf4j
public class WorkItemFieldPropertyMapper {
private static Map<String, XxxBean> fieldPropertyMap = new HashMap<>();
@Value("classpath:xxx_property.json")
private Resource resource;
@PostConstruct
public Map<String, XxxBean> getFieldPropertyFromFile() {
try {
String propertyJsonStr = IOUtils.toString(resource.getInputStream(), StandardCharsets.UTF_8.name());
List<XxxBean> fieldPropertyList = JSONObject.parseArray(propertyJsonStr, XxxBean.class);
fieldPropertyMap = fieldPropertyList.stream().collect(Collectors.toMap(XxxBean::getFieldAlmKey, Function.identity(), (v1, v2) -> v2));
} catch (IOException e) {
log.error("parse field property to map failed.");
e.printStackTrace();
}
return fieldPropertyMap;
}
// 直接获取内存中的数据
public static Map<String, XxxBean> getFieldPropertyMap() {
return fieldPropertyMap;
}
}