我是靠谱客的博主 落寞滑板,最近开发中收集的这篇文章主要介绍mysql-下划线转驼峰-转载转换函数根据数据库表的定义生成java pojo代码生成下划线转驼峰的列名的SQL语句,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

转换函数

1.需要创建自定义函数

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

2.删除函数
drop function underlineToCamel;
3.示例
select underlineToCamel('production_contract_manage');
结果:productionContractManage

原文连接:https://blog.csdn.net/qq_43565104/article/details/108821559

根据数据库表的定义生成java pojo代码

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 = '你的数据库名称' 
		AND table_schema = '你的表格名称' 
	) t

在这里插入图片描述
原文连接:https://blog.csdn.net/lyxt918/article/details/120566628

生成下划线转驼峰的列名的SQL语句

SELECT
	group_concat(
		column_name,
		' ',
	underlineToCamel ( column_name )) AS columnstring 
FROM
	information_schema.`COLUMNS` 
WHERE
	table_schema = '你的数据库名称' 
	AND table_name = '你的表格名称'

可得到
id id,establish_id establishId,con_code conCode,pro_name proName

最后

以上就是落寞滑板为你收集整理的mysql-下划线转驼峰-转载转换函数根据数据库表的定义生成java pojo代码生成下划线转驼峰的列名的SQL语句的全部内容,希望文章能够帮你解决mysql-下划线转驼峰-转载转换函数根据数据库表的定义生成java pojo代码生成下划线转驼峰的列名的SQL语句所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(39)

评论列表共有 0 条评论

立即
投稿
返回
顶部