关于 MySQL 的 boolean 和 tinyint(1)
boolean类型
MYSQL保存BOOLEAN值时用1代表TRUE,0代表FALSE,boolean在MySQL里的类型为tinyint(1),
MySQL里有四个常量:true,false,TRUE,FALSE,它们分别代表1,0,1,0,
mysql> select true,false,TRUE,FALSE;
+------+-------+------+-------+
| TRUE | FALSE | TRUE | FALSE |
+------+-------+------+-------+
| 1 | 0 | 1 | 0 |
+------+-------+------+-------+
可以如下插入boolean值:insert into [xxxx(xx)] values(true),当然也可以values(1);
举例如下:
mysql> alter table test add isOk boolean;
Query OK
mysql> desc test;
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| isOk | tinyint(1) | YES | | NULL | |
+-------+-------------+------+-----+---------+----------------+
mysql> insert into test(isOk) values(true);
Query OK
mysql> select isOk from test ;
+------+
| isOk |
+------+
| 1 |
+------+
=================
create table xs ( id int primary key, bl boolean )
这样是可以创建成功,但查看一下建表后的语句,就会发现,mysql把它替换成tinyint(1)。也就是说mysql把boolean=tinyInt了,但POJO类要定义成什么类型呢?