1、oracle中的id通过创建序列给id赋值,假设创建了序列test_seq如下:
create sequence test_seq
start with 1; --没加increment by 默认步长为1
2.使用配置类,在配置类中添加如下的代码:
@Bean
public IKeyGenerator keyGenerator() {
return new OracleKeyGenerator();
}
3.创建实体
@Data
@TableName("test")
@KeySequence(value = "test_seq", clazz = String.class)
public class Product {
//id
@TableId(value = "PID", type = IdType.INPUT)
private String pid;
//名称
private String pname;
...
}
4、说明
@KeySequence 序列主键策略(value = “test_seq”, clazz = String.class)
@TableId 主键注解