@TableId源码@TableId注解是专门用在主键上的注解,如果数据库中的主键字段名和实体中的属性名,不一样且不是驼峰之类的对应关系,可以在实体中表示主键的属性上加@Tableid注解,并指定@Tableid注解的value属性值为表中主键的字段名既可以对应上。
package com.baomidou.mybatisplus.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD})
public @interface TableId {
String value() default "";
IdType type() default IdType.NONE;
}
@TableId中type几种类型
| 值 | 解释 |
|---|---|
| AUTO | 数据库自增,必须实体加上@TableId(type = IdType.AUTO)同时数据库字段类型设为自增才可以生效 |
| NONE | MybatisPlus自动生成主键,雪花算法实现 |
| INPUT | 需要手动进行输入 |
| ASSIGN_ID | MybatisPlus自动分配id,Long、String、Integer类型 |
| ASSIGN_UUID | MybatisPlus分配UUID,String类型 |



