原始日志查询时,不从Object... obj中获取需要date类型的字段了,调用的时候容易漏写,改为反射获取date类型的字段
This commit is contained in:
@@ -135,13 +135,15 @@ public class HiveJDBC {
|
|||||||
Map<String, String> filedAndColumnMap = getColumn2FiledMap(entityClass);
|
Map<String, String> filedAndColumnMap = getColumn2FiledMap(entityClass);
|
||||||
List<String> listString = new ArrayList<String>();
|
List<String> listString = new ArrayList<String>();
|
||||||
List listObject = new ArrayList();
|
List listObject = new ArrayList();
|
||||||
List<String> columnList = null;
|
//不从Object... obj中获取需要date类型的字段了,调用的时候容易漏写,改为反射获取date类型的字段
|
||||||
if (null != obj && obj.length > 0) {
|
List<String> columnList =getDateColumn(entityClass);
|
||||||
columnList = new ArrayList<String>();
|
// List<String> columnList =null;
|
||||||
for (int i = 0; i < obj.length; i++) {
|
// if (null != obj && obj.length > 0) {
|
||||||
columnList.add(obj[i].toString().toLowerCase());
|
// columnList = new ArrayList<String>();
|
||||||
}
|
// for (int i = 0; i < obj.length; i++) {
|
||||||
}
|
// columnList.add(obj[i].toString().toLowerCase());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
// ResultSet rs = HiveJDBC.query(sql.toString());
|
// ResultSet rs = HiveJDBC.query(sql.toString());
|
||||||
ResultSetMetaData metaData = rs.getMetaData();
|
ResultSetMetaData metaData = rs.getMetaData();
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
@@ -186,7 +188,7 @@ public class HiveJDBC {
|
|||||||
} else {
|
} else {
|
||||||
mapList.put("str", listString.subList(startNum, listString.size()));
|
mapList.put("str", listString.subList(startNum, listString.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
mapList.put("str", new ArrayList());
|
mapList.put("str", new ArrayList());
|
||||||
}
|
}
|
||||||
@@ -203,6 +205,27 @@ public class HiveJDBC {
|
|||||||
return mapList;
|
return mapList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 反射获取类中date类型的字段名称
|
||||||
|
* @param type
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static List<String> getDateColumn(Class type) throws Exception {
|
||||||
|
List<String> columnList = new ArrayList<String>();
|
||||||
|
BeanInfo beanInfo = Introspector.getBeanInfo(type);
|
||||||
|
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
|
||||||
|
for (int i = 0; i < propertyDescriptors.length; i++) {
|
||||||
|
PropertyDescriptor propertyDescriptor = propertyDescriptors[i];
|
||||||
|
String name = propertyDescriptor.getName();
|
||||||
|
String fieldTypeName = propertyDescriptor.getPropertyType().getName();
|
||||||
|
if (fieldTypeName.equals("java.util.Date")) {
|
||||||
|
columnList.add(name.toLowerCase());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return columnList;
|
||||||
|
}
|
||||||
|
|
||||||
public static Object map2Obj(Map map, Class type) throws Exception {
|
public static Object map2Obj(Map map, Class type) throws Exception {
|
||||||
BeanInfo beanInfo = Introspector.getBeanInfo(type);
|
BeanInfo beanInfo = Introspector.getBeanInfo(type);
|
||||||
Object obj = type.newInstance();
|
Object obj = type.newInstance();
|
||||||
|
|||||||
Reference in New Issue
Block a user