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
iBATIS - Defining 'javaType' and 'jdbcType'
提问by peakit
While defining the resultMap
in iBatis, it provides an option to set the javaType
and jdbcType
for each property to column mapping.
resultMap
在 iBatis 中定义 时,它提供了一个选项来设置javaType
和jdbcType
为每个属性到列映射。
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 javaType
and jdbcType
?I have seen mapping where it justworks without defining these properties and in others we have to define them.
想知道什么时候应该定义javaType
和jdbcType
?我已经看到映射在没有定义这些属性的情况下它就可以工作,而在其他情况下我们必须定义它们。
EDIT:See the selected answer below for the above question.
编辑:请参阅下面为上述问题选择的答案。
Also, do we have an exhaustive list out of which javaType
and jdbcType
should be defined?
同时,我们是否有一个详尽的清单外面javaType
和jdbcType
应如何界定?
EDIT: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
编辑:javaType
应该是众所周知的类型如之一java.lang.String
,java.util.Date
而jdbcType
应该是未来的出java.sql.Types中
Thanks in advance!
提前致谢!
回答by Elbonian
For jdbcType
the 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 javaType
attribute 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 以确保所需的行为。