SELECT
concat( '\n/**\n', ' * ', v.column_comment, '\n', ' */\n', 'private ', v.dataType, ' ', v.column_name, ';' ) resultData
FROM
(
SELECT
CASE
WHEN ( data_type = 'varchar'
OR data_type = 'char'
OR data_type = 'text'
OR data_type = 'blob' ) THEN 'String'
WHEN data_type = 'int' THEN 'int'
WHEN data_type = 'bigint' THEN 'Long'
WHEN data_type = 'double' THEN 'double'
WHEN data_type = 'tinyint' THEN 'Boolean'
WHEN data_type = 'datetime' THEN 'Date'
END AS dataType,
column_name,
column_comment
FROM
information_schema. COLUMNS
WHERE
table_name = '表名' ) v
如果有其他数据类型想要转为java对应数据类型的可以自定义添加语句在上面比如:
// 这个'int'是数据库表的类型,'Integer'是要转换为java字段的类型(是把所有为'int'都转为'Integer')
WHEN data_type = 'int' THEN 'Integer'
展示效果