Why the field type of tinyint(1) is Boolean when mapping the property in po class

Problem description:

Create a table, the field type tinyint length is 1, and the field type mapped to the PO class is Boolean
tinyint(3) --> Byte
tinyint(1) --> Boolean

Reason for the problem:
1. There is no Boolean type data in MySQL; In MySQL, Boolean=="tinyint(1)
2.BOOL, BOOLEAN
These types are synonyms (synonyms) for TINYINT(1). A value of zero is considered (thought to be) false. Nonzero (not 0) values ​​are considered true
3. Tinyint(1) is only used to save bool values, only 0 and 1 do not save other values

​​If you want to save more values, use Tinyint(4), then this type will become sbyte in Ef, This is an integer.

Note: sbyte: Stores an 8-bit signed integer. The s in sbyte stands for signed, which means that the variable can be positive or negative. The minimum possible value for the sbyte variable is -128 and the maximum possible value is 127.




Solution:
1. Forcibly modify the mapping in mapResult, change the type of po attribute from Boolean to Byte
2. When querying the sql field of tinyint(1), change it to (status+0) as status
3. Avoid using tinyint(1) ) as the data type of the field

Blog reference:
About MySQL's boolean and tinyint(1)
When Mysql tinyint length is 1, it is converted into boolean type in java
http://www.cnblogs.com/joeylee/p/3878223.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326492011&siteId=291194637