java iBATIS - 定义“javaType”和“jdbcType”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4907055/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 08:34:12  来源:igfitidea点击:

iBATIS - Defining 'javaType' and 'jdbcType'

javaibatis

提问by peakit

While defining the resultMapin iBatis, it provides an option to set the javaTypeand jdbcTypefor each property to column mapping.

resultMap在 iBatis 中定义 时,它提供了一个选项来设置javaTypejdbcType为每个属性到列映射。

e.g.

例如

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

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

想知道什么时候应该定义javaTypejdbcType我已经看到映射在没有定义这些属性的情况下它就可以工作,而在其他情况下我们必须定义它们。

EDIT:See the selected answer below for the above question.

编辑:请参阅下面为上述问题选择的答案。

Also, do we have an exhaustive list out of which javaTypeand jdbcTypeshould be defined?

同时,我们是否有一个详尽的清单外面javaTypejdbcType应如何界定?

EDIT:javaTypeshould be one of the well-known types e.g. java.lang.String, java.util.Dateand jdbcTypeshould be coming out of java.sql.Types

编辑:javaType应该是众所周知的类型如之一java.lang.Stringjava.util.DatejdbcType应该是未来的出java.sql.Types中

Thanks in advance!

提前致谢!

回答by Elbonian

For jdbcTypethe documentation(for iBATIS 3) states:

对于jdbcType文档(为iBATIS 3)规定:

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

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

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

本文档的第 33 页是受支持的 JDBC 类型列表。

For the javaTypeattribute it says:

对于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.

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