概述
mysql没有直接处理的函数,需要先自定义一个函数运行函数:
CREATE FUNCTION underlineToCamel
(paramString VARCHAR(200)) RETURNS varchar(200) CHARSET utf8
DETERMINISTIC
begin
set paramString = LOWER(paramString);
set paramString = replace(paramString, ‘_a’, ‘A’);
set paramString = replace(paramString, ‘_b’, ‘B’);
set paramString = replace(paramString, ‘_c’, ‘C’);
set paramString = replace(paramString, ‘_d’, ‘D’);
set paramString = replace(paramString, ‘_e’, ‘E’);
set paramString = replace(paramString, ‘_f’, ‘F’);
set paramString = replace(paramString, ‘_g’, ‘G’);
set paramString = replace(paramString, ‘_h’, ‘H’);
set paramString = replace(paramString, ‘_i’, ‘I’);
set paramString = replace(paramString, ‘_j’, ‘J’);
set paramString = replace(paramString, ‘_k’, ‘K’);
set paramString = replace(paramString, ‘_l’, ‘L’);
set paramString = replace(paramString, ‘_m’, ‘M’);
set paramString = replace(paramString, ‘_n’, ‘N’);
set paramString = replace(paramString, ‘_o’, ‘O’);
set paramString = replace(paramString, ‘_p’, ‘P’);
set paramString = replace(paramString, ‘_q’, ‘Q’);
set paramString = replace(paramString, ‘_r’, ‘R’);
set paramString = replace(paramString, ‘_s’, ‘S’);
set paramString = replace(paramString, ‘_t’, ‘T’);
set paramString = replace(paramString, ‘_u’, ‘U’);
set paramString = replace(paramString, ‘_v’, ‘V’);
set paramString = replace(paramString, ‘_w’, ‘W’);
set paramString = replace(paramString, ‘_x’, ‘X’);
set paramString = replace(paramString, ‘_y’, ‘Y’);
set paramString = replace(paramString, ‘z’, ‘Z’);
set paramString = replace(paramString, '’, ‘’);
RETURN paramString;
end
原文链接:https://blog.csdn.net/qq_43565104/article/details/108821559
创建一个函数以后 可以直接把有下划线的列放入处理
删除函数命名 : drop function underlineToCamel;
演示:select underlineToCamel(‘java_bean_obj’) from dual ;
输出结果:javaBeanObj
人懒所以写个工具 后续再优化mybatis等等 自动生成 直接上代码 上结果对比
SELECT
CONCAT(
columnComment,
annotations,
tableField,
data_type,
(select underlineToCamel(t.column_name))
) AS 实体类,
(select underlineToCamel(t.column_name)) as aaa,
t.*
from (
SELECT
CONCAT(’/**n * ‘,COLUMN_COMMENT,’n */n’) as columnComment,
CONCAT(’@Schema(description = “’,column_name,’”)n’) as annotations,
CONCAT(’@TableField("’,COLUMN_COMMENT,’")n’) as tableField,
COLUMN_COMMENT,
(
CASE
data_type
WHEN ‘varchar’
THEN ‘private String’
WHEN ‘bigint’
THEN ‘private Long’
WHEN ‘int’
THEN ‘private Integer’
WHEN ‘date’
THEN ‘private Date’
WHEN ‘text’
THEN ‘private String’
WHEN ‘datetime’
THEN ‘private java.sql.Timestamp’
ELSE ‘NULL’
END
) AS data_type,
CONCAT(’ ‘,LOWER(column_name),’;n’) as column_name
FROM
information_schema.columns
WHERE TABLE_NAME = ‘替换自己表名’ ) t
最后
以上就是强健大白为你收集整理的Mysql 自定义函数-下划线转驼峰的全部内容,希望文章能够帮你解决Mysql 自定义函数-下划线转驼峰所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复