mysql java 根据表名转为mybatis中resultMap,部分常用类型匹配。

-- mysql java 根据表名转为mybatis中resultMap,部分常用类型匹配
select concat(
	'<result column="',
	COLUMN_NAME,
	'" property="',
	leftstr,
	if(leftstr = '',SUBSTRING(rightstr,1,1),UPPER(SUBSTRING(rightstr,1,1))),
	SUBSTRING(rightstr,2,length(rightstr)),
	'" jdbcType="',
	(case DATA_TYPE
		when 'varchar' then 'VARCHAR'
		when 'int' then 'INTEGER'
		when 'double' then 'DOUBLE'
		when 'float' then 'DOUBLE'
		when 'datetime' then 'VARCHAR'
		end),
	'" />'
) as java_variable
from (
	select 
        ORDINAL_POSITION,
	COLUMN_NAME,
	substr(COLUMN_NAME,1,instr(COLUMN_NAME,'_')-1) leftstr,
	substr(COLUMN_NAME,instr(COLUMN_NAME,'_'	)+1,
	length(COLUMN_NAME)-instr(COLUMN_NAME,'_')) rightstr,
	DATA_TYPE,
	COLUMN_COMMENT from information_schema.COLUMNS 
	where table_name = 'teacher' -- 填写所需要的表名
) a order by ORDINAL_POSITION
-- 支持mysql8.0+

posted @ 2019-06-05 14:16  只会玩卡尔  阅读(483)  评论(0编辑  收藏  举报