自定义mybatisplus自动生成id

1、加上注解

@TableId(type = IdType.ASSIGN_ID)

2、编写一个类

@Slf4j
@Component
class CustomIdGenerator implements IdentifierGenerator {

    private final AtomicLong al = new AtomicLong(1);

    @Override
    public Long nextId(Object entity) {

        final long id = al.getAndAdd(1);

        return System.currentTimeMillis();
    }
}

猜你喜欢

转载自blog.csdn.net/m0_56195330/article/details/128601649