mybatis-plus3+postgresql insert 自增序列配置

使用mybatis-plus版本为 3.1.0,springboot版本为2.2.4.RELEASE

  1. MP3版本弃用配置文件方式,改用@Bean方式注入,添加组件
@Slf4j
@Component("MybatisPlusKeyGenerator")
public class MybatisPlusKeyGenerator {

    @Bean
    public PostgreKeyGenerator postgreKeyGenerator(){
        return new PostgreKeyGenerator();
    }
}
  1. 实体类中添加@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;}
发布了2 篇原创文章 · 获赞 0 · 访问量 22

猜你喜欢

转载自blog.csdn.net/guashengzan0281/article/details/104312290