-
Notifications
You must be signed in to change notification settings - Fork 56
Description
我的项目中需要将时间戳保留到至少毫秒级别,这需要表字段设置为 timestamp 类型,长度设为3,默认值设为 CURRENT_TIMESTAMP(3)。而 com.gitee.sunchenbin.mybatis.actable.constants.MySqlTypeConstant 这个枚举下,定义了 TIMESTAMP 的 lengthCount 是 0,这导致在表初始化和表结构变更时,无法将 timestamp 的字段赋长度。
关键代码在 com.gitee.sunchenbin.mybatis.actable.manager.system.SysMysqlCreateTableManagerImpl#getAllFields 方法的第594行左右:
param.setFileTypeLength(mySqlTypeAndLength.getLengthCount());
if (mySqlTypeAndLength.getLengthCount() == 1) {
param.setFieldLength(mySqlTypeAndLength.getLength());
} else if (mySqlTypeAndLength.getLengthCount() == 2) {
param.setFieldLength(mySqlTypeAndLength.getLength());
param.setFieldDecimalLength(mySqlTypeAndLength.getDecimalLength());
}
我的解决办法比较粗糙,是将该枚举的源代码拷贝至项目下,将 TIMESTAMP 的 lengthCount 重写为 1,并赋默认值为 3,利用 类加载的双亲委派特性 覆盖A.CTable-Frame包内的枚举。但该办法仅适用于我的项目,还期望作者能考虑一下兼容timestamp类型的长度。