MyBatis中的JdbcType映射

Java项目涉及到数据库交互,以往常用的是JDBC,现在则有Hibernate、Mybatis等这些持久化支持。

项目中用到了MyBatis,和JDBC最显著的区别,就是SQL语句配置化,通过xml文件定义SQL语句,当然JDBC也可以将SQL配置化,需要定制开发,MyBatis则直接支持这种方法。

官方对于MyBatis的介绍,

MyBatis is a first class persistence framework with support for custom SQL, stored procedures and advanced mappings. MyBatis eliminates almost all of the JDBC code and manual setting of parameters and retrieval of results. MyBatis can use simple XML or Annotations for configuration and map primitives, Map interfaces and Java POJOs (Plain Old Java Objects) to database records.

简单来讲,MyBatis几乎屏蔽了所有JDBC代码,用一种简单的xml,或者注解,就能完成数据库交互。

xml配置文件,可用MyBatis自己定义的数据类型,引自:http://www.mybatis.org/mybatis-3/configuration.html

Associated JDBC type can be specified by two means:

Adding a jdbcType attribute to the typeHandler element (for example: jdbcType=“VARCHAR”).

Adding a @MappedJdbcTypes annotation to your TypeHandler class specifying the list of JDBC types to associate it with. This annotation will be ignored if the jdbcType attribute as also been specified.

例如下面的配置,指定companyid参数类型为BIGINT,


select a.meetingno
from xxx a
where a.companyid = #{companyid, jdbcType=BIGINT}

对于jdbcType,MyBatis的API文档有说明,引自:http://www.mybatis.org/mybatis-3/apidocs/reference/org/apache/ibatis/type/JdbcType.html

在这里插入图片描述
另外,这篇文章,给出了JdbcType和Oracle以及MySQL,相互之间的映射关系,比较详细,引自:http://blog.csdn.net/loongshawn/article/details/50496460

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值