-- 查询数据表结构
SELECT
CONCAT('"e.',SUBSTRING(COLUMN_NAME,1),',"+'),COLUMN_NAME,',',COLUMN_TYPE,
column_comment
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE table_schema = 'xcb'
and table_name = 't_product';
-- 生成Java实体类
SELECT
CONCAT('@Column(name="',SUBSTRING(COLUMN_NAME,2),'")'),
case
when COLUMN_NAME='fid' then CONCAT('@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid") private String ',SUBSTRING(COLUMN_NAME,2),';')
when DATA_TYPE like '%char%' or DATA_TYPE like '%text%' then CONCAT('private String ',SUBSTRING(COLUMN_NAME,2),';')
when DATA_TYPE like '%int%' then CONCAT('private Integer ',SUBSTRING(COLUMN_NAME,2),';')
when DATA_TYPE like '%float%' then CONCAT('private Float ',SUBSTRING(COLUMN_NAME,2),';')
when DATA_TYPE like '%decimal%' then CONCAT('private BigDecimal ',SUBSTRING(COLUMN_NAME,2),';')
when DATA_TYPE like '%date%' then CONCAT('@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date ',SUBSTRING(COLUMN_NAME,2),';')
when DATA_TYPE like '%timestamp%' then CONCAT('@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date ',SUBSTRING(COLUMN_NAME,2),';')
else COLUMN_NAME
end,CONCAT('//',column_comment)
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE table_schema = 'xcb'
and table_name = 't_score_order';
-- 生成VSCode实体
SELECT
case
when DATA_TYPE like '%char%'
then CONCAT(SUBSTRING(COLUMN_NAME,2),':string;')
when DATA_TYPE like '%int%' or DATA_TYPE like '%float%' or DATA_TYPE like '%decimal%'
then CONCAT(SUBSTRING(COLUMN_NAME,2),':number;')
when DATA_TYPE like '%date%' or DATA_TYPE like '%timestamp%'
then CONCAT(SUBSTRING(COLUMN_NAME,2),':Date;')
else COLUMN_NAME
end as a,CONCAT('//',COLUMN_COMMENT) as b
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE table_schema = 'xcb'
and table_name = 't_coach';