数据库字段转实体类字段


DROP FUNCTION IF EXISTS f_spiltStr;
CREATE FUNCTION `f_spiltStr`(DATA1 varchar(50)) RETURNS varchar(1000) CHARSET utf8
BEGIN  
      SET @length = LENGTH(DATA1) - LENGTH(REPLACE(DATA1,'_',''));  
      SET @i = 1;  
            set @result  = '';
      WHILE @i<@length+1
        DO  
          set @i = @i + 1;  
          SET @val=SUBSTRING_INDEX(SUBSTRING_INDEX(DATA1,'_',@i),'_',-1); 
                  set @val = CONCAT(upper(left(@val,1)),substring(@val,2));
          set @result =  CONCAT(@result,@val);
            END WHILE;  
        set @result =   CONCAT(SUBSTRING_INDEX(DATA1,'_',1),@result);
  RETURN @result;
END

select 
'private',
case DATA_TYPE
when 'bigint' then 'Integer'
when 'int' then 'Integer'
when 'varchar' then 'String'
when 'decimal' then 'BigDecimal'
when 'datetime' then 'Date'
when 'timestamp' then 'Date'
end,
CONCAT(f_spiltStr( COLUMN_NAME),';'),
CONCAT('//',COLUMN_COMMENT)
from information_schema.columns where table_schema='flint_shop' and table_name='sys_menu'

要求: 数据库字段必须是以“_”分割 转到对象上是驼峰形式的字段

例如:sys_menu_name ------> sysMenuName 

先执行上面的创建本地函数  然后执行下面的查找语句

 

posted @ 2018-06-04 16:10  樊金龙  阅读(347)  评论(0编辑  收藏  举报