欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

使用sql生成表对应的CRUD语句和表对应java实体类的实例变量

程序员文章站 2022-05-25 11:25:57
...

该sql运行于mysql 无 SELECTCONCAT('SELECT ',GROUP_CONCAT(COLUMN_NAME),' FROM ',TABLE_NAME)FROMinformation_schema. COLUMNSWHERETABLE_NAME = 'worker'; 其中 表名为worker SELECTCONCAT("UPDATE worker SET ",GROUP_CONCAT(COLUMN_NAME,"= ()")," WHERE

该sql运行于mysql
SELECT
	CONCAT(
		'SELECT ',
		GROUP_CONCAT(COLUMN_NAME),
		' FROM ',
		TABLE_NAME
	)
FROM
	information_schema. COLUMNS
WHERE
	TABLE_NAME = 'worker'; 
其中 表名为worker 
SELECT
	CONCAT(
		"UPDATE worker SET ",
		GROUP_CONCAT(
			COLUMN_NAME,
			"= ()"
		),
		" WHERE Id = "
	)
FROM
	information_schema. COLUMNS
WHERE
	TABLE_NAME = 'worker';
SELECT
    CONCAT(
        'INSERT INTO worker( ',
        GROUP_CONCAT(COLUMN_NAME),
        ') VALUES (',
        GROUP_CONCAT(
            CONCAT('()')
        ),
        ')'
    )
FROM
    information_schema. COLUMNS
WHERE
    TABLE_NAME = 'worker' ;
SELECT
    CONCAT(
        'private ',
        (
            CASE
            WHEN DATA_TYPE = 'varchar' THEN 'String '
            WHEN DATA_TYPE = 'datetime' THEN
                'Date '
            WHEN DATA_TYPE = 'int' THEN
                'int '
	    WHEN DATA_TYPE = 'float' THEN
                'float '
            END
        ),
        COLUMN_NAME,' ;	//',COLUMN_COMMENT
    )
FROM
    information_schema. COLUMNS
WHERE TABLE_NAME = 'worker' ;