使用oracle脚本生成VO和Dao

话不多说直接上代码。

  生成VO的脚本:

SELECT '/**' || T2.COMMENTS || '*/ @Column(name="' || T1.COLUMN_NAME || '")' ||
       'private ' || CASE
         WHEN T1.DATA_TYPE LIKE 'VARCHAR%' THEN
          'String '
         WHEN T1.DATA_TYPE LIKE 'DATE%' THEN
          'Date '
         WHEN T1.DATA_SCALE <> NULL OR T1.DATA_SCALE <> 0 THEN
          'Double '
         WHEN T1.DATA_TYPE LIKE 'NUMBER%' THEN
          'int '
         WHEN T1.DATA_TYPE LIKE 'Timestamp%' THEN
          'Timestamp '
       END || LOWER(SUBSTR(T1.COLUMN_NAME, 1, 1)) ||
       SUBSTR(REPLACE(INITCAP(T1.COLUMN_NAME), '_', ''), 2) || ';'
  FROM USER_TAB_COLUMNS T1, USER_COL_COMMENTS T2
 WHERE T1.TABLE_NAME = T2.TABLE_NAME
   AND T1.COLUMN_NAME = T2.COLUMN_NAME
   AND T1.TABLE_NAME IN ('表名')

  生成DaO的脚本:

  

SELECT '/**' || T2.COMMENTS || '*/ ' ||
       'private ' || CASE
         WHEN T1.DATA_TYPE LIKE 'VARCHAR%' THEN
          'String '
         WHEN T1.DATA_TYPE LIKE 'DATE%' THEN
          'Date '
         WHEN T1.DATA_SCALE <> NULL OR T1.DATA_SCALE <> 0 THEN
          'Double '
         WHEN T1.DATA_TYPE LIKE 'NUMBER%' THEN
          'int '
         WHEN T1.DATA_TYPE LIKE 'Timestamp%' THEN
          'Timestamp '
       END || LOWER(SUBSTR(T1.COLUMN_NAME, 1, 1)) ||
       SUBSTR(REPLACE(INITCAP(T1.COLUMN_NAME), '_', ''), 2) || ';'
  FROM USER_TAB_COLUMNS T1, USER_COL_COMMENTS T2
 WHERE T1.TABLE_NAME = T2.TABLE_NAME
   AND T1.COLUMN_NAME = T2.COLUMN_NAME
   AND T1.TABLE_NAME IN ('表名')

将生成出来的数据复制到Java类里,格式化就OK了。

原文地址:https://www.cnblogs.com/pluto-charon/p/11029405.html