Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dao数字字段对应MySQL中的字段 #594

Closed
enzozhong opened this issue Jan 25, 2014 · 4 comments
Closed

Dao数字字段对应MySQL中的字段 #594

enzozhong opened this issue Jan 25, 2014 · 4 comments
Assignees
Milestone

Comments

@enzozhong
Copy link
Contributor

49中Dao

Byte --> TINYINT
Integer --> INT
Long --> BIGINT

问题是为什么Short对应的也是 TINYINT?
建议换成 SMALLINT 或者 MEDIUMINT

@zozoh
Copy link
Member

zozoh commented Jan 25, 2014

哇,这么细腻,有必要吗?

@enzozhong
Copy link
Contributor Author

细致一点没啥不好哈~
因为我一个Bean里面用呢Short,结果写入的时候报错,too long了,所以才发现了这个问题~

@zozoh
Copy link
Member

zozoh commented Jan 26, 2014

如果你要限制特殊的大小,你可以

@Column("n")
@ColDefine(type=ColType.INT, width=2)    // 相当于 INT(2)
private short num;

对于 Mysql 的逻辑,参加如下代码:

@Override
protected String evalFieldType(MappingField mf) {
    if (mf.getCustomDbType() != null)
        return mf.getCustomDbType();
    // Mysql 的精度是按照 bit
    if (mf.getColumnType() == ColType.INT) {
        int width = mf.getWidth();
        if (width <= 0)
            return "INT(32)";
        else if (width <= 4) {
            return "TINYINT(" + (width * 4) + ")";
        } else if (width <= 8) {
            return "INT(" + (width * 4) + ")";
        }
        return "BIGINT(" + (width * 4) + ")";
    }
    if (mf.getColumnType() == ColType.BINARY) {
        return "MediumBlob"; //默认用16M的应该可以了吧?
    }
    // 其它的参照默认字段规则 ...
    return super.evalFieldType(mf);
}

@enzozhong
Copy link
Contributor Author

一开始我也是用@Coldefine来搞这个问题,总感觉能写一行的,干嘛要写2行呢,框架就应该是去做脏活的嘛。既然都写MYSQL的类了,也是想对MYSQL有更好的支持,为什么就不能更加的细分呢??

上面的代码也只能知道是CloType.INT,有办法知道BEAN中字段的类型吗??
可能的话,就根据字段类型来区分对待,细分一点。

zozoh added a commit that referenced this issue Jan 28, 2014
@ghost ghost assigned zozoh Jan 28, 2014
@zozoh zozoh closed this as completed Jan 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants