SpringBoot integration Mybatisplus common comment

Notes common entity classes:

ID: MP default fill (based on algorithms snow increment ID)

Database table names have requirements: for example: a unified prefix (mp_user, etc.), use annotations @TableName, such as:   

@TableName("mp_user")
public class User {}  

Field entity class field name does not correspond, for example:

public class User {
    //姓名
    @TableField("name")
    private String realName;
}

Three ways to exclude non-table fields:

Scenario: variable entity classes need to use does not exist in the database field

1. Direct identification with transient, transient identified by the variable can not be serialized

@Data
@TableName("mp_user")
public class User {
    //备注
    private transient String remark;

}

2. Mark static variables, generates get (), set () method. Called directly by the class name

@Data
@TableName("mp_user")
public class User {
    //备注
    private static String remark;

    public static String getRemark() {
        return remark;
    }

    public static void setRemark(String remark) {
        User.remark = remark;
    }
}

3. be solved by using annotations

@Data
@TableName("mp_user")
public class User {
    //备注
    @TableFiles(exist=false)
    private static String remark;
}

 

 

 

 

 

 

 

 

   

@TableName("mp_user")
public class User {}  

Guess you like

Origin www.cnblogs.com/zhukf/p/12132922.html
Recommended