iBATIS-定义"javaType"和"jdbcType" [英] iBATIS - Defining 'javaType' and 'jdbcType'

查看:219
本文介绍了iBATIS-定义"javaType"和"jdbcType"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iBatis中定义resultMap时,它提供了一个选项,可将每个属性的javaTypejdbcType设置为列映射.

While defining the resultMap in iBatis, it provides an option to set the javaType and jdbcType for each property to column mapping.

例如

<resultMap id="employee" class="com.mycompany.Employee">
   <result property="firstName" column="first_name" javaType="?" jdbcType="?"/>
</resultMap>

想知道何时应该定义javaTypejdbcType??我已经看到了 just 在不定义这些属性的情况下以及在其他属性中的映射我们必须定义它们.

Wanted to know that when we should be defining the javaType and jdbcType? I have seen mapping where it just works without defining these properties and in others we have to define them.

编辑:请参见下面针对上述问题选择的答案.

See the selected answer below for the above question.

此外,我们是否还有一个详尽的列表,应在其中定义javaTypejdbcType?

Also, do we have an exhaustive list out of which javaType and jdbcType should be defined?

编辑:javaType应该是众所周知的类型之一,例如java.lang.Stringjava.util.DatejdbcType应该来自 java.sql.类型

javaType should be one of the well-known types e.g. java.lang.String, java.util.Date and jdbcType should be coming out of java.sql.Types

提前谢谢!

推荐答案

对于jdbcType

For jdbcType the documentation (for iBATIS 3) states:

只有在插入,更新或删除时可为空的列才需要JDBC类型.

The JDBC type is only required for nullable columns upon insert, update or delete.

本文档第33页上列出了受支持的JDBC类型.

On page 33 in this document is a list of supported JDBC types.

对于javaType属性,它表示:

如果您要映射到JavaBean,

iBATIS通常可以确定类型.但是,如果要映射到HashMap,则应显式指定javaType以确保所需的行为.

iBATIS can usually figure out the type if you’re mapping to a JavaBean. However, if you are mapping to a HashMap, then you should specify the javaType explicitly to ensure the desired behaviour.

这篇关于iBATIS-定义"javaType"和"jdbcType"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆