mysql表字段生成java实体类_驼峰

sql来源

https://blog.csdn.net/qq_32360501/article/details/85163014

sql语句

    SELECT
    	CONCAT("/**\r","* ",a.COLUMN_COMMENT,"\r*/\r",'private ', (CASE 
    	WHEN a.DATA_TYPE ='int' THEN 'Integer '
    WHEN a.DATA_TYPE ='date' THEN 'String '
    	WHEN a.DATA_TYPE ='VARCHAR' THEN 'String '
    	WHEN a.DATA_TYPE= 'datetime' THEN 'Date '
    	else 'null '
    	END
    ),_2aAa(COLUMN_NAME) ,";") COLUMN_NAME 
    FROM
    	information_schema.COLUMNS  a
    WHERE
    	table_name = '*****';

函数 _2aAa

DELIMITER $$
CREATE FUNCTION _2aAa(oldName varchar(20)) RETURNS varchar(50)
BEGIN
SET @newName = oldName;
SET @ind = INSTR(@newName, '_');


WHILE @ind > 0 DO

SET @leftStr = LEFT (@newName, @ind - 1);


SET @rightStr = RIGHT (@newName, LENGTH(@newName) - @ind);


IF @rightStr IS NOT NULL
AND @rightStr != '' THEN

SET @rightStr = concat(
	upper(LEFT(@rightStr, 1)),
	RIGHT (
		@rightStr,
		length(@rightStr) - 1
	)
);


END
IF;


SET @newName = concat(@leftStr, @rightStr);
SET @ind = INSTR(@newName, '_');
END WHILE;
RETURN @newName;
END $$
DELIMITER;

你可能感兴趣的:(java)