Mysql: How to Use JFinal data
Preface: It is a great honor to have a small problem today. The getInt () and getLong () Methods of JFinal are associated with mysql data types. If the int type field in mysql uses unsigned, JFinal uses getLong (). If the int type field does not use unsigned, JFinal uses getInt (), otherwise, a Type Mismatch Error occurs.
First, let's take a look at the data types of mysql. Here we only look at the data types of the int type
Int [(m)] |
Signed value:-2147683648 to 2147683647 (-231 to 231-1) Unsigned value: 0 to 4294967295 (0 to 232-1) 4 bytes |
This means that if your data field is like this
'Uid' int (11) not null default '0' COMMENT 'user id'
M = 11 is correct, because considering "-" (negative number), the maximum length is 11 characters.
If your data field is like this
'Uid' int (11) unsigned not null comment 'user id'
M = 11 is meaningless, because the maximum length is 10 characters. If you are professional, your data field should be like this.
'Uid' int (10) unsigned not null comment 'user id'
For more information about mysql Data, see http://www.cnblogs.com/kwishly/archive/2012/04/19/2457824.html.
The JFinal data type is the same. Here we only focus on the getLong () and getInt () methods.
/** * Get attribute of mysql type: int, integer, tinyint(n) n > 1, smallint, mediumint */ public Integer getInt(String attr) { return (Integer)attrs.get(attr); } /** * Get attribute of mysql type: bigint, unsign int */ public Long getLong(String attr) { return (Long)attrs.get(attr); }
Note the difference between unsigned int and int.
Java int data
System.out.println("2147683647"); System.out.println("4294967295"); System.out.println(Integer.MAX_VALUE);//2147483647
In this way, you will understand why JFinal is designed like that.
Summary: Knowledgeable and knowledgeable.