Mysql: How to Use JFinal data

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.