//获取实体类set方法
public Object getObject(Object object, TRSResultSet res) throws Exception {
Field[] fields = object.getClass().getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
fields[i].setAccessible(true);
String type = fields[i].getType().getSimpleName();
if (fields[i].getName().equalsIgnoreCase("serialVersionUID")
|| fields[i].getName().equalsIgnoreCase("version")) {
continue;
}
if (type.equals("Date")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
if (res.getDate(fields[i].getName()) != null) {
fields[i].set(object, sdf.parse(res.getString(fields[i].getName())));
}
} else if (type.equals("Long")) {
fields[i].set(object, res.getLong(fields[i].getName()));
} else if (type.equals("int")) {
fields[i].set(object, res.getInt(fields[i].getName()));
} else if (type.equals("double")) {
fields[i].set(object, res.getDouble(fields[i].getName()));
} else {
fields[i].set(object, res.getString(fields[i].getName()));
}
}
return object;
}
public Object getObject(Object object, TRSResultSet res) throws Exception {
Field[] fields = object.getClass().getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
fields[i].setAccessible(true);
String type = fields[i].getType().getSimpleName();
if (fields[i].getName().equalsIgnoreCase("serialVersionUID")
|| fields[i].getName().equalsIgnoreCase("version")) {
continue;
}
if (type.equals("Date")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
if (res.getDate(fields[i].getName()) != null) {
fields[i].set(object, sdf.parse(res.getString(fields[i].getName())));
}
} else if (type.equals("Long")) {
fields[i].set(object, res.getLong(fields[i].getName()));
} else if (type.equals("int")) {
fields[i].set(object, res.getInt(fields[i].getName()));
} else if (type.equals("double")) {
fields[i].set(object, res.getDouble(fields[i].getName()));
} else {
fields[i].set(object, res.getString(fields[i].getName()));
}
}
return object;
}