Mybatis中什么时候应该声明jdbcType
转:http://blog.csdn.net/l799069596/article/details/52052777
疑问来自于,有时候Mapper.xml中
pid = #{pid,jdbcType=INTEGER}
pid = #{pid}
都可以用
那么问题来了,
Mybatis中什么时候应该声明jdbcType?
当Mybatis不能自动识别你传入对象的类型时。
什么情况下,Mybatis不能自动识别我的传入类型?
例如:当你传入空值的时候。
简而言之,加上肯定不会报错。
来源:Is jdbcType necessary in a MyBatis mapper?
引用:
As you mentioned yourself, you need to specify the jdbcType when passing null values for parameters.
Some databases need to know the value's type even if the value itself is NULL. For this reason, for maximum portability, it's the JDBC specification itself that requires the type to be specified and MyBatis needs to pass it along since it's build on top of JDBC.
From the MyBatis documentation:
The JDBC type is only required for nullable columns upon insert, update or delete. This is a JDBC requirement, not a MyBatis one. So even if you were coding JDBC directly, you'd need to specify this type – but only for nullable values.
Most of the times you don't need to specify the jdbcType as MyBatis is smart enough to figure out the type from the objects you are working with. But if you send your parameters to the MyBatis statement inside a HashMap, for example, and one of the parameters is null, MyBatis won't be able to determine the type of the parameter by looking at the HashMap because the HashMap is just a generic Container and null itself carries no type information. At that point it would be o good idea to provide the jdbcType so that switching the database implementation later on does not cause any issues with null values.
Mybatis中什么时候应该声明jdbcType的更多相关文章
- MyBatis中jdbcType=INTEGER、VARCHAR作用
Mapper.xml中 pid = #{pid,jdbcType=INTEGER} pid = #{pid} 都可以用 Mybatis中什么时候应该声明jdbcType? 当Mybatis不能自动识别 ...
- 记自己在mybatis中设置jdbcType的一个坑
项目是用ssm搭建的.主要是为app数据接口.其中有一个需求就app想要查询一段时间内某个用户的测量信息,所以app给我后端传递了3个参数,分别是appuserId(String),startDate ...
- Mybatis中的jdbcType的作用
使用MyBatis框架做更新操作时,在该字段需要更新的内容为空时,就会出现1111错误,也就是无效的列类型,这个时候你就要使用jdbcType.至于什么时候要使用到javaType我还没遇到过,而且我 ...
- mybatis 中jdbctype和javatype的对应关系
1:mybatis 中jdbctype和javatype的对应关系 JDBC Type Java Type CHAR String VARCHAR String LONGVARCHAR String ...
- Mybatis中jdbcType和javaType对应关系
Mybatis中javaType和jdbcType对应关系 JDBC Type Java Type CHAR String VARCHAR ...
- UncategorizedSQLException Mybatis中jdbcType的作用
使用MyBatis框架做更新操作时,在该字段需要更新的内容为空时,就会出现1111错误,也就是无效的列类型,这个时候你就要使用jdbcType.至于什么时候要使用到javaType我还没遇到过,而且我 ...
- Mybatis使用- Mybatis JdbcType与Oracle、MySql数据类型对应列表 ; Mybatis中javaType和jdbcType对应关系
Mybatis JdbcType与Oracle.MySql数据类型对应列表 Mybatis JdbcType Oracle MySql JdbcType ARRAY JdbcType BIG ...
- mybatis中jdbcType的作用和是否必须
1. mybatis中 jdbcType 时间类型 当jdbcType = DATE 时, 只传入了 年月日 jdbcType = TIMESTAMP , 年月日+ 时分秒 2. jdbcType ...
- mybatis中jdbcType和javaType
1.MyBatis 通过包含的jdbcType类型 BIT.FLOAT.CHAR .TIMESTAMP . OTHER .UNDEFINEDTINYINT .REAL .VARCHAR .BINARY ...
随机推荐
- Navicat和DBeaver的查询快捷键
1.Navicat for MySQL(连接MySQL数据库的工具) ctrl + r 执行查询页中所有的sql语句 ctrl + shift + r 只运行选中的sql语句 2.DBeaver(支持 ...
- 【springmvc+mybatis项目实战】杰信商贸-4.maven依赖+PO对+映射文件
上一篇我们附件的增删改查功能全部完成.但是我们的附件有一个字段叫做“类型”(ctype),这里我们要使用数据字典,所以对于这一块我们要进行修改. 首先介绍一下数据字典 数据字典它是一个通用结构,跟业务 ...
- ubuntu server guide 学习笔记
1. 软件包 1.1. dpkg dpkg -l dpkg -l | grep apache2 dpkg -L ufw dpkg -S /etc/host.conf dpkg -i zip_3.0-4 ...
- 关于Filter中ServletRequest强转HttpServletRequest问题
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOE ...
- Java IO(文件操作工具类)
FileOperate实现的功能: 1. 返回文件夹中所有文件列表 2. 读取文本文件内容 3. 新建目录 4. 新建多级目录 5. 新建文件 6. 有编码方式的创建文件 7. 删除文件 8. 删除指 ...
- [leetcode-783-Minimum Distance Between BST Nodes]
Given a Binary Search Tree (BST) with the root node root, return the minimum difference between the ...
- gcc与g++区别以及相关参数详解
---恢复内容开始--- 原文链接:g++和gcc的区别 一 .二者区别 gcc和g++都是GNU(一个组织)的编译器. 1.对于.c后缀的文件,gcc把它当做是C程序:g++当做是C++程序: 2. ...
- 【week2】 构建之法 读后感及问题
上一次读后感涵盖前五章的内容包括个人技术,结对合作,小组项目等.本周作业的燃尽图以及站立会议是关于<构建之法>第六章的内容,所以关于这一章的读后感涵盖在上两篇博客中. 第七章 MSF 介绍 ...
- concurrenthashmap jdk1.8
参考:https://www.jianshu.com/p/c0642afe03e0 CAS的思想很简单:三个参数,一个当前内存值V.旧的预期值A.即将更新的值B,当且仅当预期值A和内存值V相同时,将内 ...
- java zip 压缩与解压
java zip 压缩与解压 import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java. ...