通过beanUtil简化部分代码

master
星期八 5 years ago
parent 88d75d3e6f
commit 0daf439758
  1. 10
      panda-jdbc/src/main/java/org/panda/jdbc/BeanHander.java

@ -1,13 +1,16 @@
package org.panda.jdbc; package org.panda.jdbc;
import org.panda.beans.util.BeanUtil;
import org.panda.code.uitl.ReflectionUtil; import org.panda.code.uitl.ReflectionUtil;
import org.panda.jdbc.annotation.Column; import org.panda.jdbc.annotation.Column;
import org.panda.jdbc.sql.BeanSqlUtil; import org.panda.jdbc.sql.BeanSqlUtil;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.ResultSetMetaData; import java.sql.ResultSetMetaData;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.List;
/** /**
* @author qi * @author qi
@ -25,12 +28,13 @@ public class BeanHander implements ResultSetHandler {
public Object handler(ResultSet rs) { public Object handler(ResultSet rs) {
try { try {
Object bean = clazz.newInstance(); Object bean = BeanUtil.instantiateClass(clazz);
ResultSetMetaData metadata = rs.getMetaData(); ResultSetMetaData metadata = rs.getMetaData();
//数据总数
int coulumnCount = metadata.getColumnCount(); int coulumnCount = metadata.getColumnCount();
List<Field> fieldList = BeanUtil.getAllField(clazz);
Field [] fields = clazz.getDeclaredFields(); for (Field f:fieldList){
for (Field f:fields){
String fieldName = f.getName(); String fieldName = f.getName();
String columnName = BeanSqlUtil.caseToHump(fieldName); String columnName = BeanSqlUtil.caseToHump(fieldName);
try { try {

Loading…
Cancel
Save