Mybatis Parameters JDBC Type
Mybatis的sqlmap中Parameters的jdbcType参数可以不设置,Parameters 官方文档中解释:
The JDBC Type is required by JDBC for all nullable columns, if null is passed as a value.
You can investigate this yourself by reading the JavaDocs for the PreparedStatement.setNull() method.
Mybatis在处理参数具体类型时从TypeHandlerRegistry中获取具体的TypeHandler。
1 | /** |
继续看了mysql.jdbc对null值的处理,发现其实这个jdbcType在设置值时根本没用到,可能是为了以后使用吧。直接上代码。1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24/**
* Set a parameter to SQL NULL
*
* <p>
* <B>Note:</B> You must specify the parameters SQL type (although MySQL
* ignores it)
* </p>
*
* @param parameterIndex
* the first parameter is 1, etc...
* @param sqlType
* the SQL type code defined in java.sql.Types
*
* @exception SQLException
* if a database access error occurs
*/
public void setNull(int parameterIndex, int sqlType) throws SQLException {
synchronized (checkClosed().getConnectionMutex()) {
setInternal(parameterIndex, "null"); //$NON-NLS-1$
this.isNull[parameterIndex - 1 + getParameterIndexOffset()] = true;
this.parameterTypes[parameterIndex - 1 + getParameterIndexOffset()] = Types.NULL;
}
}
小生不才,以上如有描述有误的地方还望各位不吝赐教 !^_^!