Customize mybatisplus to automatically generate id

1. Add annotations

@TableId(type = IdType.ASSIGN_ID)

2. Write a class

 

@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();
    }
}

 

Guess you like

Origin blog.csdn.net/m0_56195330/article/details/128601649