mybatis-mp 是一款高度ORM的框架,api简单又方便,学习成本非常低:https://gitee.com/mybatis-mp
mybatis-mp 虽然是基于mybatis,但是它却是一款高实现ORM的框架,可同时支持不同数据库,这意味着你可以用一份代码,在不同数据库中运行
例如常见的ID自增,有的数据库ID自己会自增,有的只能指定序列自增,用了mybatis-mp,可省大部分心了,自动适应;
@Data
@Table
public class IdTest {
@TableId //默认
@TableId(dbType = DbType.H2, value = IdAutoType.AUTO) //H2
@TableId(dbType = DbType.SQL_SERVER, value = IdAutoType.AUTO) //SQL_SERVER
@TableId(dbType = DbType.PGSQL, value = IdAutoType.SQL, sql = "select nextval('id_test_id_seq')")
@TableId(dbType = DbType.ORACLE, value = IdAutoType.SQL, sql = "select id_test_seq.NEXTVAL FROM dual")
private Long id;
private LocalDateTime createTime;
}
保存代码(无差异) :
IdTestMapper idTestMapper = session.getMapper(IdTestMapper.class);
IdTest idTest = new IdTest();
idTest.setCreateTime(LocalDateTime.now());
idTestMapper.save(idTest);