1.创建MybatisPlusConfig配置类

@Configuration
public class MybatisPlusConfig {
        /**
     * 自定义主键生成:生成的 当前时间 + 随机数的格式
     * @return
     */
    @Bean
    public IdentifierGenerator idGenerator() {
        return new IdentifierGenerator() {
            @Override
            public Number nextId(Object entity) {
                return null;
            }

            @Override
            public String nextUUID(Object entity) {
                return DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN) + IdUtil.simpleUUID();
            }
        };
    }
}

2.yml添加如下配置

mybatis-plus:
  global-config:
    db-config:
      id-type: ASSIGN_UUID

 

相关文章:

  • 2021-07-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-19
猜你喜欢
  • 2022-01-08
  • 2022-12-23
  • 2021-11-22
  • 2021-12-18
  • 2020-12-25
  • 2022-12-23
相关资源
相似解决方案