Boolean type
MySQL saves a Boolean value with 1 for true,0 representing False,boolean in MySQL with type tinyint (1),
There are four constants in MySQL: True,false,true,false, which represent 1,0,1,0 respectively,
Mysql> Select True,false,true,false;
+------+-------+------+-------+
| TRUE | FALSE | TRUE | FALSE |
+------+-------+------+-------+
| 1 | 0 | 1 | 0 |
+------+-------+------+-------+
You can insert a Boolean value as follows: INSERT INTO [xxxx (XX)] VALUES (true), and of course values (1);
Examples are as follows:
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 |
+------+
=================
MySQL does not have a Boolean type. This is also a very strange phenomenon. Example:
CREATE TABLE xs (ID int primary key, BL Boolean) |
This is a good way to create a success, but looking at the statement after the build, you will find that MySQL replaced it with tinyint (1). In other words, MySQL has boolean=tinyint, but what type of Pojo class to define? because of inertial thinking, it is also defined as type in the Java class. Then use the <s:check/> tag in struts. This creates a serious problem. <s:check> is a Boolean, and Pojo is defined as byte. This data can never be submitted, was blocked by struts intercept. The workaround is to define a Boolean in the Pojo class, defined in MySQL as tinyint (1). ------TINYINT (1) or ENUM (' true ', ' false ')-------
MySQL's Boolean and tinyint (1)