1) 仅仅需要让实体类(JavaBean)继承 Model类且实现主键指定方法 pkVal**(),即可开启 AR 之旅。
注意:pkVal**() 方法内要 **return id**;
package com.wzy.pojo;import com.baomidou.mybatisplus.activerecord.Model;import com.baomidou.mybatisplus.annotations.TableField;import com.baomidou.mybatisplus.annotations.TableId;import com.baomidou.mybatisplus.annotations.TableName;import com.baomidou.mybatisplus.enums.IdType;import lombok.*;import java.io.Serializable;@AllArgsConstructor@NoArgsConstructor@ToString@Getter@Setter@TableName(value = "tbl_employee")//起别名public class Employees extends Model<Employees> {//1继承Model/*** @TableId:* value:指定表中的主键列的列名,如果实体属性名与列名一致,可以省略不指定。* type:指定主键策略。IdType.AUTO为自增*/// @TableId(value = "id",type = IdType.AUTO)private Integer id;//@TableField(value = "last_name")private String lastName;private String email;private Integer gender;private Integer age;//2、实现pkVal()方法@Overrideprotected Serializable pkVal() {return id;}}
