下面列出了怎么用org.springframework.boot.bind.RelaxedNames的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public ConfigurationMetadataProperty getPropertyMetadata(String propertyName) {
if (cpExec == null) {
init();
}
if (cachedProperties != null) {
// generate and try relaxed variants
for (String relaxedName : new RelaxedNames(propertyName)) {
if (cachedProperties.containsKey(relaxedName)) {
return cachedProperties.get(relaxedName);
} else {
// try to interpret array notation (strip '[index]' from pName)
Matcher mArrNot = PATTERN_ARRAY_NOTATION.matcher(relaxedName);
if (mArrNot.matches()) {
return cachedProperties.get(mArrNot.group(1));
} else {
// try to interpret map notation (see if pName starts with a set of known map props)
for (String mapPropertyName : getMapPropertyNames()) {
if (relaxedName.startsWith(mapPropertyName)) {
return cachedProperties.get(mapPropertyName);
}
}
}
}
}
}
return null;
}
public static void main(String[] args) {
// 生成属性名称 "user.HOME-PAGE" 的所有松散格式
RelaxedNames relaxedNames = new RelaxedNames("user.homePage");
// 输出所有松散格式
relaxedNames.forEach(System.out::println);
}
private boolean checkType(String type, String text, ClassLoader cl) throws IllegalArgumentException {
Class<?> clazz = ClassUtils.resolveClassName(type, cl);
if (clazz != null) {
try {
parser.parseType(text, clazz);
} catch (Exception e1) {
if (clazz.isEnum()) {
// generate and try relaxed variants of value
for (String relaxedName : new RelaxedNames(text)) {
try {
parser.parseType(relaxedName, clazz);
return true;
} catch (Exception e2) {
// try another variant
}
if (canceled) {
break;
}
}
return false;
} else {
try {
// handle a few specific cases where no direct constructor from string or converter exist
switch (type) {
case "java.nio.file.Path":
Paths.get(text);
return true;
case "java.util.Locale":
LocaleUtils.toLocale(text);
return true;
case "java.time.Duration":
DurationStyle.detectAndParse(text);
return true;
case "org.springframework.util.unit.DataSize":
DataSize.parse(text);
return true;
case "java.lang.Class":
cl.loadClass(text);
return true;
default:
return false;
}
} catch (Exception e3) {
return false;
}
}
}
}
// unresolvable/unknown class, assume user knows what is doing
return true;
}