数据库表字段要求:
1.所有字段都是小写
2.每个字段多个单词之间用下划线分割
例如: user_name
user_address_one
数据库:
1.将字符转换成驼峰的数据库函数:
CREATE FUNCTION `f_spiltStr`(DATA1 varchar(50),splitStr VARCHAR(10)) RETURNS varchar(255) CHARSET utf8
BEGIN
SET @result ='';
SET @length = LENGTH(DATA1) - LENGTH(REPLACE(DATA1,splitStr,''));
SET @i = 0;
WHILE @i<@length+1
DO
set @i = @i + 1;
SET @val=SUBSTRING_INDEX(SUBSTRING_INDEX(DATA1,splitStr,-@i),splitStr,1);
IF @i=(@length+1) THEN
SET @result =concat(@result,REVERSE(@val));
ELSE
SET @start =UPPER(left(@val,1));
SET @end = REVERSE(substring(@val,2,(length(@val)-1)));
SET @v = concat(@end ,@start);
SET @result =concat(@result,@v);
END IF;
END WHILE;
RETURN REVERSE(@result);
END;
2. 查询方法:
SELECT
'private',
case DATA_TYPE
WHEN 'bigint' THEN 'Integer'
WHEN 'varchar' THEN 'String'
WHEN 'int' THEN 'Integer'
WHEN 'decimal' THEN 'Decimal'
WHEN 'bigint' THEN 'Integer'
WHEN 'datetime' THEN 'sunbox.core.util.Date'
end,
CONCAT(f_spiltStr(COLUMN_NAME,'_'),';'),
CONCAT('//',COLUMN_COMMENT)
from information_schema.COLUMNS where TABLE_NAME = 'card_change_fill_rec'
注释:
card_change_fill_rec 是表名称