根据表名生成实体类

package com.cmb.ccrm.mng;

import java.sql.Connection;

import java.sql.DatabaseMetaData;

import java.sql.ResultSet;

import org.junit.Test;

import com.cmb.ccrm.base.BaseTest;

import com.google.common.base.CaseFormat;

public class test extends BaseTest {

 @Test  public void 生成实体类() throws Exception {

  String tableName = "s51_tsk_rel_cust";

  Connection conn = connection.getConnection();

  DatabaseMetaData databaseMetaData = conn.getMetaData();

  ResultSet tableRet = databaseMetaData.getTables(null, "%", tableName, new String[] { "TABLE" });

  while (tableRet.next()) {

   String columnName;    String columnType;

   ResultSet colRet = databaseMetaData.getColumns(null, "%", tableName, "%");

   while (colRet.next()) {     columnName = colRet.getString("COLUMN_NAME");

    columnType = colRet.getString("TYPE_NAME").toLowerCase();

    String remarks = colRet.getString("REMARKS");

    String columType = "";

    switch (columnType) {

    case "varchar":

     columType = "String";

     break;

    case "int":

     columType = "int";      break;

    default:

     columType = "String";

    }

    System.out.println("/**");

    System.out.println("*" + remarks);

    System.out.println("*/");      //    System.out.println(CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, "test-data")); //    System.out.println(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, "test_data")); //    System.out.println(CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, "test_data")); // //    System.out.println(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, "testdata")); //    System.out.println(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, "TestData")); //    System.out.println(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, "testData"));

    System.out.println("private " + columType + "\t"       + CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, columnName) + ";");

    System.out.println();

   }

  }

 }

}

转载于:https://www.cnblogs.com/wu1254/p/10718964.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值