java程序 package cn.jxau.factory;import java.io.IOException;import java.util.Properties;public class DaoFactory {private static Properties prop = new Properties();// 将工厂类设计成单例模式private DaoFactory() {try {prop.load(Da
package cn.jxau.factory; import java.io.IOException; import java.util.Properties; public class DaoFactory { private static Properties prop = new Properties(); // 将工厂类设计成单例模式 private DaoFactory() { try { prop.load(DaoFactory.class.getClassLoader().getResourceAsStream( "dao.properties")); } catch (IOException e) { // TODO Auto-generated catch block throw new RuntimeException(); } } private static DaoFactory instance = new DaoFactory(); public static DaoFactory getInstance() { return instance; } // 送进来的是什么类型工厂就为你造什么类型的dao,java中把所有的类也抽取成了一个类叫Class public static配置文件,用接口名指向实现类的全限定名T getdao(Class clazz) { // 获得传进来的接口名用于反射出一个对象实例 String name = clazz.getSimpleName();// 得到一个不带包名的接口名 String classname = prop.getProperty(name);//通过具体的配置文件获取具体的类名 T dao = null; try { dao = (T) Class.forName(classname).newInstance();//反射实例出一个对象 } catch (Exception e) { // TODO Auto-generated catch block throw new RuntimeException(e); } return dao; } }
UserDao=cn.jxau.dao.impl.UserDaoJdbcImpl