Commit f6316c38 authored by xianjun's avatar xianjun

修改工具类

parent d1686dde
...@@ -306,13 +306,24 @@ public class ObjectHelper { ...@@ -306,13 +306,24 @@ public class ObjectHelper {
return toName; return toName;
} }
/**
* 获取字段处理名称
*
* @param fromName 字段名称
* @return 属性名称
*/
private static String getObjectFieldName(String fromName) {
String toName = fromName.replace("_", "");
return toName;
}
/** /**
* 获取实体的字段 * 获取实体的字段
* *
* @param cls 需要获取的类型 * @param cls 需要获取的类型
* @return 获取字段之间的对应关系 * @return 获取字段之间的对应关系
*/ */
private static HashMap<String, MethodField> getInitTypeField(Class<?> cls) { private static HashMap<String, MethodField> getInitTypeField(Class<?> cls, boolean isTableField) {
HashMap<String, MethodField> typeCache = new LinkedHashMap<String, MethodField>(); HashMap<String, MethodField> typeCache = new LinkedHashMap<String, MethodField>();
List<Field> fields = new ArrayList<Field>(); List<Field> fields = new ArrayList<Field>();
...@@ -332,7 +343,13 @@ public class ObjectHelper { ...@@ -332,7 +343,13 @@ public class ObjectHelper {
if (Modifier.isStatic(field.getModifiers())) { if (Modifier.isStatic(field.getModifiers())) {
continue; continue;
} }
String toName = getSimpleFieldName(field.getName()); String toName;
if (isTableField) {
toName = getSimpleFieldName(field.getName());
} else {
toName = getObjectFieldName(field.getName());
}
MethodField obj = getField(typeCache, field.getName(), toName); MethodField obj = getField(typeCache, field.getName(), toName);
if (obj.getField() == null) { if (obj.getField() == null) {
obj.setField(field); obj.setField(field);
...@@ -382,7 +399,24 @@ public class ObjectHelper { ...@@ -382,7 +399,24 @@ public class ObjectHelper {
if (MAP_CACHE.containsKey(type)) { if (MAP_CACHE.containsKey(type)) {
typeCache = MAP_CACHE.get(type); typeCache = MAP_CACHE.get(type);
} else { } else {
typeCache = getInitTypeField(type); typeCache = getInitTypeField(type, true);
MAP_CACHE.put(type, typeCache);
}
return typeCache;
}
/**
* 获取一个表中的字段
*
* @param type
* @return
*/
public static HashMap<String, MethodField> getObjectTypeField(Class<?> type) {
HashMap<String, MethodField> typeCache;
if (MAP_CACHE.containsKey(type)) {
typeCache = MAP_CACHE.get(type);
} else {
typeCache = getInitTypeField(type, false);
MAP_CACHE.put(type, typeCache); MAP_CACHE.put(type, typeCache);
} }
return typeCache; return typeCache;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment