Mybatis-plus reverse engineering automatically generates code - add @TableField to the entity class field

Mybatis-plus reverse engineering automatically generates code - add @TableField to the entity class field

1. Introducing dependencies

Introduce mybatis-plus-generator dependency, the version should be the same as your mybatis-plus version

<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-generator</artifactId>
    <version>3.4.0</version>
</dependency>

Two, the code

1. Versions below 3.5.1

Add the following code at the appropriate position in CodeGenerator.java

StrategyConfig strategy = new StrategyConfig();
TableFill createTime = new TableFill("create_time", FieldFill.INSERT);
TableFill updateTime = new TableFill("update_time", FieldFill.INSERT_UPDATE);
List<TableFill> tableFills = Arrays.asList(createTime,updateTime);
strategy.setTableFillList(tableFills);

2. Version 3.5.1 and above

Entity policy configuration

method illustrate example
nameConvert(INameConvert) name conversion implementation
superClass(Class<?>) set parent class BaseEntity.class
superClass(String) set parent class com.baomidou.global.BaseEntity
disableSerialVersionUID Disable generation of serialVersionUID Default value: true
enableColumnConstant Enable generating field constants Default value: false
enableChainModel Open the chain model Default value: false
enableLombok Open the lombok model Default value: false
enableRemoveIsPrefix Open the Boolean type field and remove the is prefix Default value: false
enableTableFieldAnnotation Generate field annotations when generating entities Default value: false
enableActiveRecord Open ActiveRecord model Default value: false
versionColumnName(String) Optimistic lock field name (database)
versionPropertyName(String) Optimistic lock attribute name (entity)
logicDeleteColumnName(String) Tombstone field name (database)
logicDeletePropertyName(String) tombstone attribute name (entity)
we Naming strategy for mapping database tables to entities Default underline to camel case naming: NamingStrategy.underline_to_camel
columnNaming Naming strategy for mapping database table fields to entities The default is null, if it is not specified, it will be executed according to naming
addSuperEntityColumns(String…) Add parent class public field
addIgnoreColumns(String…) Add ignore field
addTableFills(IFill…) Add table field population
addTableFills(List) Add table field population
idType(IdType) Global primary key type
convertFileName(ConverterFileName) Convert file name
formatFileName(String) Format file name
new StrategyConfig.Builder()
    .entityBuilder()
    .superClass(BaseEntity.class)
    .disableSerialVersionUID()
    .enableChainModel()
    .enableLombok()
    .enableRemoveIsPrefix()
    .enableTableFieldAnnotation()
    .enableActiveRecord()
    .versionColumnName("version")
    .versionPropertyName("version")
    .logicDeleteColumnName("deleted")
    .logicDeletePropertyName("deleteFlag")
    .naming(NamingStrategy.no_change)
    .columnNaming(NamingStrategy.underline_to_camel)
    .addSuperEntityColumns("id", "created_by", "created_time", "updated_by", "updated_time")
    .addIgnoreColumns("age")
    .addTableFills(new Column("create_time", FieldFill.INSERT))
    .addTableFills(new Property("updateTime", FieldFill.INSERT_UPDATE))
    .idType(IdType.AUTO)
    .formatFileName("%sEntity")
    .build();

Three, more

For more information, please refer to mybatis-plus official website

Guess you like

Origin blog.csdn.net/weixin_52067659/article/details/128397935