您好,我有以下字符串,我正在尝试针对 hibernate createAlias 和查询限制进行拆分。
我需要将字符串分成三部分。
employeeProfile.userProfile.shortname
1. employeeProfile.userProfile
2. userProfile
3. userProfile.shortName
我还希望它能够动态地执行不同长度的字符串。
employeeProfile.userProfile.anotherClass.shortname
1. employeeProfile.userProfile.anotherClass
2. userProfile.anotherClass
3. anotherClass.shortName
使用以下代码,除了第三个之外,我能够使其大部分工作。
public void hasAlias(Criteria t, final Map<String, Object> map) {
for (Map.Entry<String, Object> entry : map.entrySet()) {
String key = entry.getKey();
if (key != null && key.contains(".")) {
key = key.substring(0, key.lastIndexOf("."));
String value = key.contains(".") ? key.substring(key.lastIndexOf(".") + 1, key.length()) : key;
t.createAlias(key, value);
}
}
}
有人可以帮我获得第三名吗?
最佳答案
关于java - 按句点拆分字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19692433/