使用Mybatis查询tinyint(1)字段数据,返回值为Map类型,那么tinyint(1)的数据默认会转化为boolean类型数据.
为什么会转换成boolean?
Mysql官方参考文档关于布尔类型的说明:
BOOL, BOOLEAN
These types are synonyms(同义词) for TINYINT(1). A value of zero is considered(认为是) false. Nonzero(不为0) values are considered true
Tinyint(1) 就只用来保存 bool 值 只有0和1 不要保存其他的值
解决方案
1.在jdbcUrl添加参数:tinyInt1isBit=false(默认为true)
不推荐使用,每个人的处理方式不一样,会影响到业务。
2.避免使用长度为1的tinyint类型字段存储数字格式的数据; 如果要保存多的值,就用 Tinyint(4) Tinyint(1) 与 Tinyint(4)的区别