集成环境
spring boot
mybatis-plus 3.3.0
sharding
迁移改造点
oracle 表名字段名小写是需要使用双引号
oracle 没有limit
oracle ID自增需要借助序列
oracle 空串与NULL等价,均存为NULL
oracle 表名字段名小写是需要使用双引号
类com.baomidou.mybatisplus.core.config.GlobalConfig.DbConfig中存在相关配置
capitalMode=true即可
oracle 没有limit
limit 应借助Pagenation插件实现,使用page获取其中一页
oracle ID自增需要借助序列
使用KeySequence注解以及KeyGenerator进行,相关底层代码见com.baomidou.mybatisplus.core.injector.methods.Insert#injectMappedStatement
oracle 空串与NULL等价,均存为NULL
-
插入值使用代码默认填充,屏蔽mysql和oracle的区别,具体见注解中TableField的fill属性,如FieldFill.INSERT
-
更新时仅更新非空串,见update-strategy中FieldStrategy
配置文件如下
mybatis-plus:
mapper-locations: classpath:mapper/*.xml
configuration:
#log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
map-underscore-to-camel-case: true
global-config:
db-config:
capital-mode: true # 大写
id-type: 2 # INPUT
insert-strategy: IGNORED # 默认填充
update-strategy: NOT_EMPTY # 非空串才更新
需要声明keyGenerator,在config类中增加如下代码配合KeySequence使用
@Bean
public OracleKeyGenerator oracleKeyGenerator(){
return new OracleKeyGenerator();
}
结语
本实践尚未达到oracle和mysql无代码改动迁移,后续需继续推进