使用mybatis-plus版本为 3.1.0,springboot版本为2.2.4.RELEASE
- MP3版本弃用配置文件方式,改用@Bean方式注入,添加组件
@Slf4j
@Component("MybatisPlusKeyGenerator")
public class MybatisPlusKeyGenerator {
@Bean
public PostgreKeyGenerator postgreKeyGenerator(){
return new PostgreKeyGenerator();
}
}
- 实体类中添加@KeySequence注解,并在对应主键上添加@TableId注解
@Data
@TableName("t_user_expand")
@KeySequence(value = "t_user_expand_id_seq")
@EqualsAndHashCode(callSuper = false)
public class UserExpand extends Model<UserExpand> {
@Override
protected Serializable pkVal() {
return id;
}
@TableId(type = IdType.AUTO)
private long id;}