MyBatisPlus 之 常用注解

常用注解

  1、@TableId

    /**
     * TableId
     *  value 指定表中主键列的列名,如果实体属性名与列名一致,可以省略不指定
     *  type 指定主键策略
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

  2、@TableName

/**
 * MP 会默认使用实体类的类名到数据库中找对应的表
 */
@TableName(value = "tbl_employee")
public class Employee {}

  3、@TableField

  用于设置数据库中对应的字段名称,如下:

    @TableField(value = "last_name")
    private String lastName;
    private String email;
    private Integer gender;
    private Integer age;

    @TableField(exist = false)
    private Double salary;

    使用该注解的 value 值来指定数据库对应的字段名,还有一个 exist 属性,用来标识该属性是否作为数据库的表字段,值为 false 时,不作为数据库的字段。

原文地址:https://www.cnblogs.com/niujifei/p/15332711.html