mysql text类型对应mybatis jdbctype类型
mysql 的 text 类型对应 java 中的数据类型是 string。
对应mybatis的类型是 longvarchar 。
例:
<result column="field1" property="field1" jdbctype="longvarchar" />
注意:
- 在mybatis支持的jdbc类型中是没有 text 类型的
- 如果在 mapper.xml 中指定了 text ,会导致解析出错,无法启动。
贴一下mybatis 官网列出的支持的 jdbc 类型:

mybatis中jdbctype映射数据类型对照表
在mybatisd的映射文件mapper.xml中,会用jdbctype把java类映射数据库表字段,有关映射关系做个笔记,方便查阅。
| jdbctype | oracle | mysql | |
|---|---|---|---|
| jdbctype | array | ||
| jdbctype | bigint | bigint | |
| jdbctype | binary | ||
| jdbctype | bit | bit | |
| jdbctype | blob | blob | blob |
| jdbctype | boolean | ||
| jdbctype | char | char | char |
| jdbctype | clob | clob | 修改为text |
| jdbctype | cursor | ||
| jdbctype | date | date | date |
| jdbctype | decimal | decimal | decimal |
| jdbctype | double | number | double |
| jdbctype | float | float | float |
| jdbctype | integer | integer | integer |
| jdbctype | longvarbinary | ||
| jdbctype | longvarchar | long varchar | |
| jdbctype | nchar | nchar | |
| jdbctype | nclob | nclob | |
| jdbctype | null | ||
| jdbctype | numeric | numeric/number | numeric/ |
| jdbctype | nvarchar | ||
| jdbctype | other | ||
| jdbctype | real | real | real |
| jdbctype | smallint | smallint | smallint |
| jdbctype | struct | ||
| jdbctype | time | time | |
| jdbctype | timestamp | timestamp | timestamp/datetime |
| jdbctype | tinyint | tinyint | |
| jdbctype | undefined | ||
| jdbctype | varbinary | ||
| jdbctype | varchar | varchar | varchar |
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
发表评论