使用oracle腳本生成VO和Dao

話很少說直接上代碼。spa

  生成VO的腳本:code

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的腳本:blog

  

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了。class

相關文章
相關標籤/搜索