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 ...
随机推荐
- JavaScript 数组操作方法 和 ES5数组拓展
JavaScript中数组有各种操作方法,以下通过举例来说明各种方法的使用: 数组操作方法 push 在数组最后添加一个元素 var arr=[3,4,5,6] console.log(arr) // ...
- 利用AWS的EC2实例配合Putty访问Google账户
首先,我们需要一个amazon的帐号,该帐号可以开始AWS服务,第一次使用时需要绑定信用卡并扣1美元,然后再退还到我们的卡中,就是要验证一下信用卡帐户的有效性哦.有了这个帐号就可以尽情地享受AWS提供 ...
- day21 TFRecord格式转换MNIST并显示
首先简要介绍了下TFRecord格式以及内部实现protobuf协议,然后基于TFRecord格式,对MNIST数据集转换成TFRecord格式,写入本地磁盘文件,再从磁盘文件读取,通过pyplot模 ...
- 微信小程序:封装全局的promise异步调用方法
微信小程序:封装全局的promise异步调用方法 一:封装 function POST(url, params) { let promise = new Promise(function (resol ...
- NFS服务搭建使用
需求:由于线上业务有一些数据存在了Redis数据库和mysql数据库中了,导致了数据较大迁移起来比较麻烦,所以准备搭建NFS来做WEB的共享磁盘,存储这些数据. 服务端搭建: 查看本机关于nfs的包 ...
- 新人学PHP,认为手动搭建环境而苦恼吗?这篇文章告诉你多简单!
本教程适用于初学PHP,想了解手动搭建PHP环境的童鞋. 一键环境和高手勿喷. 本教程以下列版本软件为例: 所需软件目录 我在这里的目录结构是(个人习惯) 安装与配置 apache 双击安装Apach ...
- 买卖股票的最佳时机I II III IV
I 假设有一个数组,它的第i个元素是一支给定的股票在第i天的价格.如果你最多只允许完成一次交易(例如,一次买卖股票),设计一个算法来找出最大利润. II 假设有一个数组,它的第i个元素是一个给定的股票 ...
- ZOJ 1403 F-Safecracker
https://vjudge.net/contest/67836#problem/F "The item is locked in a Klein safe behind a paintin ...
- struts如何在Action类中操作request,session
在servlet中,通过request.getparameter与setparameter来实现后端与前端jsp页面的数据交互,那么在struts中,也有几种方式来操作request,session实 ...
- idea超炫的自定义模板
idea超炫的自定义模板 idea 有些快捷键 sout -> System.out.println() ,输入sout,idea能自动补全代码, 这种约定的快捷方式大大提高了效率, 而id ...