

package com.sj.utils;import java.lang.reflect.Field;import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Method;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.S
package com.sj.utils;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class BaseDao {
	/**
	*查询方法
	*/
	public static List findAll(Object obj,Connection conn) throws Exception{
	Class clazz=obj.getClass();
	//获取传入的实体中的所有的方法
	Method[] m=clazz.getMethods();
	//获取传入实体中的所有的属性
	Field[] f=clazz.getDeclaredFields();
	//建立结果集List接收对象
	List list=new ArrayList();
	//创建sql语句
	String sql="select * from "+obj.getClass().getSimpleName().toLowerCase();
	System.out.println(sql);
	//System.out.println(sql);
	//预编译sql语句
	PreparedStatement pst=conn.prepareStatement(sql);
	//执行预编译的语句,获取结果集
	ResultSet rs=pst.executeQuery();
	//从结果集中循环取出放入结果集List
	while(rs.next()){
	Object obj2=clazz.newInstance();
	
	for(int i=0;i