java通过newInstance生成对应实体类型

public static void main(String[] args) throws SQLException {
        DmCustomerExcellent dmCustomerExcellent = new DmCustomerExcellent();
         Connection conn = getConnection();
         Map<String, Class> map = new HashMap<>();
         map.put("dm_customer_excellent", DmCustomerExcellent.class);
         String sql = "select * from dm_customer_excellent where rownum = 1 ";
         Class class1 = map.get("dm_customer_excellent");
         try {
            Object testCustomerExcellent = class1.newInstance();
            if(testCustomerExcellent instanceof DmCustomerExcellent){
                DmCustomerExcellent tt = (DmCustomerExcellent)testCustomerExcellent;
                tt.setActperbusi2("-adfa-f--");
                System.out.println(tt.getActperbusi2());
            }
        } catch (InstantiationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

 

posted @ 2018-10-30 16:46  十月围城小童鞋  阅读(563)  评论(0编辑  收藏  举报