美文网首页mybatis-plus
7.MybatisPlus 主键策略

7.MybatisPlus 主键策略

作者: 神奇作手 | 来源:发表于2020-03-25 22:07 被阅读0次

1.局部主键策略实现

在对应的实体类中添加注解

//    @TableId(type = IdType.AUTO)//主键自增
//    @TableId(type = IdType.NONE)//主键非自增
//    @TableId(type = IdType.UUID)//主键UUID
//    @TableId(type = IdType.ID_WORKER)//生成数字雪花算法ID
//    @TableId(type = IdType.ID_WORKER_STR)//生成字符串雪花算法ID
    @TableId//指明此字段为主键id,默认雪花算法
    private Long id;//主键

2.全局主键策略实现

在配置文件中配置全局策略

# mapper.xml文件位置
mybatis-plus:
  mapper-locations: classpath:mapper/*.xml
  global-config:
    db-config:
      id-type: uuid  #使用UUID主键

相关文章

网友评论

    本文标题:7.MybatisPlus 主键策略

    本文链接:https://www.haomeiwen.com/subject/xllfuhtx.html